We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Databound ComboBoxAutoComplete

Hi, I''m trying use ComboBoxAutoComplete and assing DataView as DataSource. How do I set DisplayMember and DisplayValue to this Combo. How to retrive selected Value from ComboBoxAutoCompete. thanks in advance, Shahzad

10 Replies

AR Anupama Roy Syncfusion Team November 22, 2005 06:18 AM UTC

Hi Shahzad, Sorry for the delayed response. The following code snippet illustrates your requirement. private void Form1_Load(object sender, System.EventArgs e) { this.oleDbDataAdapter1.Fill(this.dataSet11); this.dataView1 = new System.Data.DataView (this.dataSet11.Employees); this.comboBoxAutoComplete1.AutoCompleteControl.DataSource = this.dataView1 ; this.comboBoxAutoComplete1.DisplayMember = "FirstName"; this.comboBoxAutoComplete1.AutoCompleteControl.Columns.Add(new AutoCompleteDataColumnInfo("EmployeeID", 20, false)); this.comboBoxAutoComplete1.AutoCompleteControl.Columns.Add(new AutoCompleteDataColumnInfo("LastName", 60, true)); this.comboBoxAutoComplete1.AutoCompleteControl.Columns.Add(new AutoCompleteDataColumnInfo("FirstName", 60, true)); this.comboBoxAutoComplete1.AutoCompleteControl.Columns[2].MatchingColumn = true; this.comboBoxAutoComplete1.DataBindings.Add("Text", this.dataSet11.Tables[0], "FirstName"); } Here is the sample that populates a ComboBoxAutoComplete with DataView as its DataSource. Please let me know if you need further assistance. Thanks for your interest in Syncfusion products. Regards, Anu

comboBoxAutoComplete_37037.zip


AS Abdul Shahzad November 30, 2005 02:25 PM UTC

Thanks Anupama. That works fine for me. The only difficulty now is how to get the selected value in the autocomplete combo when user submits the form(WinForms). Any help on this will be much appreciated. Thanks in advance, Shahzad


AR Anupama Roy Syncfusion Team December 1, 2005 05:19 AM UTC

Hi Shahzad, Inorder to get the values corresponding to the selected value in the ComboBoxAutoComplete, we can make use of the AutoCompleteItemSelected Event''s ItemArray property. This will hold the information about the currently selected item and the first item in this array will be the first column of the matching item and so on for the sub-items. Please include this code snippet in the sample project I had sent earlier to see whether this meets your requirement. private void comboBoxAutoComplete1_AutoCompleteControl_AutoCompleteItemSelected(object sender, Syncfusion.Windows.Forms.Tools.AutoCompleteItemEventArgs args) { for(int i=0;i Please let me know if you need further assistance. Thanks for your continued interest in Syncfusion products. Best Regards, Anu


AR Anupama Roy Syncfusion Team December 1, 2005 05:23 AM UTC

Hi Shahzad, The code snippet seems to be incomplete in the above post.Please refer to this. private void comboBoxAutoComplete1_AutoCompleteControl_AutoCompleteItemSelected(object sender, Syncfusion.Windows.Forms.Tools.AutoCompleteItemEventArgs args) { for(int i=0;i Thanks, Anu.


AR Anupama Roy Syncfusion Team December 1, 2005 05:26 AM UTC

Hi Shahzad, Sorry for the inconvienience caused.The post does not seem to get updated properly. Here is the syntax of the for loop I have used. for(int i=0;i > >Hi Shahzad, > >The code snippet seems to be incomplete in the above post.Please refer to this. > > > >private void comboBoxAutoComplete1_AutoCompleteControl_AutoCompleteItemSelected(object sender, Syncfusion.Windows.Forms.Tools.AutoCompleteItemEventArgs args) >{ > for(int i=0;i { > this.autoLabel1.Text = this.autoLabel1.Text +"" + args.ItemArray[i].ToString(); > } >} > > >Thanks, > >Anu.


AR Anupama Roy Syncfusion Team December 1, 2005 05:41 AM UTC

Hi Shahzad, Please refer to the sample attached. Thanks, Anu.

37037_modified.zip


AS Abdul Shahzad December 1, 2005 08:15 AM UTC

Hi Anupama, Thanks for the quick response. The code you have sent allows to get the selected value on for the event AutocompleteItemSelected. My form has other controls user will update some other control on the form without touching the combobox and submits the form for update. In this case I want to retirve the selected value of combobox. How this can be achieved? Hope my query is clear? Thanks, Shahzad


AR Anupama Roy Syncfusion Team December 5, 2005 06:10 AM UTC

Hi Shahzad, Have you tried using the SelectedValue property of comboBoxAutoComplete inorder to get the associated value? The below given code snippet will always return the selected value eventhough you have not triggered any events. MessageBox.Show (this.comboBoxAutoComplete1.SelectedValue .ToString ()); Please let me know if this does not satisfy your requirement. Thanks, Anu.


AS Abdul Shahzad December 5, 2005 08:19 AM UTC

Hi Anupama, comboBoxAutoComplete.SelectedValue.ToString() always returns and the system crashes with Object Reference not set to an instance error. Syncfusion Support Forum : http://syncfusion.com/Support/forums/message.aspx?MessageID=11072 states that "ComboBoxAutoComplete control is not provided through its SelectedValue property" Any pointers on how to retrieve the selected value. Thanks, Shahzad


AR Anupama Roy Syncfusion Team December 5, 2005 03:54 PM UTC

Hi Shahzad, The above mentioned Exception error might occur when the dataSource is set to a dataTable.Sometimes this occurs with the .NET ComboBox also. Are you using DataTable as datasource in your scenario?I have modified the previously attached sample.Please take a look it and let me know whether you get any Exception error in this. Thanks, Anu.

37037_modified0.zip

Loader.
Live Chat Icon For mobile
Up arrow icon