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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind generic list with the ComboBoxAdv?

Platform: WinForms |
Control: ComboBoxAdv |
Published Date: August 4, 2015 |
Last Revised Date: May 22, 2019

You can bind the ComboBoxAdv with Generic List. Refer to the following steps to achieve this requirement.

 

1)Initialize the Class and the Properties based on your requirement.

2)Populate the List with required details.

3)Proceed to assign as ComboBoxAdv DataSource.

 

The following code example demonstrates the same.

 

C#

List<Country> CountryList = new List<Country>();
//Adds the item into the list
CountryList.Add(new Country { Key = "India" });
CountryList.Add(new Country { Key = "US" });
CountryList.Add(new Country { Key = "UK" });
CountryList.Add(new Country { Key = "China" });
//Binds the list to the ComboBoxAdv
comboBoxAdv1.DataSource = CountryList;
comboBoxAdv1.DisplayMember = "Key";
private void comboBoxAdv1_SelectedIndexChanged(object sender, EventArgs e)
{
    this.listBox1.Items.Clear();
    //Gets the ComboBoxAdv SelectedItem
    Country selectedCountry = comboBoxAdv1.SelectedItem as Country;
    this.listBox1.Items.Add(selectedCountry.Key); 
}
//Specifies the List
public class Country
{
    public string Key {get; set;}
}

 

VB

Dim CountryList As New List(Of Country)()
'Adds the item into the list
CountryList.Add(New Country With {.Key = "India"})
CountryList.Add(New Country With {.Key = "US"})
CountryList.Add(New Country With {.Key = "UK"})
CountryList.Add(New Country With {.Key = "China"})
'Binds the list to the ComboBoxAdv
comboBoxAdv1.DataSource = CountryList
comboBoxAdv1.DisplayMember = "Key"
Private Sub comboBoxAdv1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles comboBoxAdv1.SelectedIndexChanged
 Me.listBox1.Items.Clear()
 'Gets the ComboBoxAdv SelectedItem
 Dim selectedCountry As Country = TryCast(comboBoxAdv1.SelectedItem, Country)
 Me.listBox1.Items.Add(selectedCountry.Key)
End Sub
'Specifies the List
Public Class Country
   Private privateKey As String
   Public Property Key() As String
    Get
     Return privateKey
    End Get
    Set(ByVal value As String)
     privateKey = value
    End Set
   End Property
End Class

 

Showing selected item of ComboBoxAdv displayed in ListBox

Figure 1:The selected item of the ComboBoxAdv is displayed in ListBox.

 

Sample Links:

C#: http://www.syncfusion.com/downloads/support/directtrac/141940/ze/ComboBoxList-1025859467

VB: http://www.syncfusion.com/downloads/support/directtrac/141940/ze/ComboBoxList_VB-587598701

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon