Category / Section
How to select the item through index in WinForms SfComboBox?
1 min read
You can select the combobox item based on the index value of WinForms SfComboBox control by using SelectedIndex property. You can also select the item using SelectedItem property. Refer the below code for your reference.
C#
List<State> list = GetData(); SfComboBox sfComboBox1 = new SfComboBox(); sfComboBox1.Size = new Size(150, 28); sfComboBox1.Location = new Point(138, 56); sfComboBox1.DataSource = list; //Bind the Display member and Value member to the data source sfComboBox1.DisplayMember = "DispValue"; sfComboBox1.ValueMember = "SfValue"; sfComboBox1.ComboBoxMode = Syncfusion.WinForms.ListView.Enums.ComboBoxMode.SingleSelection; sfComboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; sfComboBox1.AutoCompleteSuggestMode = Syncfusion.WinForms.ListView.Enums.AutoCompleteSuggestMode.Contains; sfComboBox1.MaxDropDownItems = 10; //Select the item based on index sfComboBox1.SelectedIndex = list[1].SfValue; //Select the item based on item sfComboBox1.SelectedItem = list[1]; this.Controls.Add(sfComboBox1);
VB
Dim list As List(Of State) = GetData() Dim sfComboBox1 As New SfComboBox() sfComboBox1.Size = New Size(150, 28) sfComboBox1.Location = New Point(138, 56) sfComboBox1.DataSource = list 'Bind the Display member and Value member to the data source sfComboBox1.DisplayMember = "DispValue" sfComboBox1.ValueMember = "SfValue" sfComboBox1.ComboBoxMode = Syncfusion.WinForms.ListView.Enums.ComboBoxMode.SingleSelection sfComboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend sfComboBox1.AutoCompleteSuggestMode = Syncfusion.WinForms.ListView.Enums.AutoCompleteSuggestMode.Contains sfComboBox1.MaxDropDownItems = 10 'Select the item based on index sfComboBox1.SelectedIndex = list(1).SfValue 'Select the item based on item sfComboBox1.SelectedItem = list(1) Me.Controls.Add(sfComboBox1)
Output:
Sample: View sample in GitHub.