Binding the WinComboBox control to a data source will automatically populate it with items. In order to bind the combobox to a data source, the DataSource and (optionally) DataMember properties must be set.
The following table provides a listing of the supported data sources:
Data Source | Description |
---|---|
DataTable | Represents one table of in-memory data. |
DataView | Represents a databindable, customized view of a DataTable for sorting, filtering, searching, editing, and navigation. |
DataSet | Represents an in-memory cache of data. |
DataViewManager | Contains a default DataViewSettingCollection for each DataTable in a DataSet. |
Any component that implements the IListSource interface | Provides functionality to an object to return a list that can be bound to a data source. |
Any component that implements the IList interface | Represents a collection of objects that can be individually accessed by index |
Jagged arrays | An array whose elements are arrays. |
VB.NET |
Copy Code |
---|---|
Dim combo As New WinComboBox() oleDbDataAdapter1.Fill( dataSet11 ) combo.DataSource = dataSet11 combo.DataMember = "Orders" combo.Location = New Point( 10 , 10 ) Me.Controls.Add( combo ) |
C# |
Copy Code |
---|---|
WinComboBox combo = new WinComboBox(); oleDbDataAdapter1.Fill( dataSet11 ); combo.DataSource = dataSet11; combo.DataMember = "Orders"; combo.Location = new Point( 10 , 10 ); this.Controls.Add( combo ); |
The next example demonstrates how to bind the WinComboBox control to a Jagged array. If items are added, removed, or modified in the jagged array from outside of the combobox, then the jagged array must be reassigned to the DataSource property in order for the modifications to be reflected in the combobox.
VB.NET |
Copy Code |
---|---|
Dim combo As New WinComboBox() Dim data(9)() As Object data(0) = New Object(3) {"Canada", 31500000, "Ottawa", "12.2 ºc"} data(1) = New Object(3) {"Switzerland", 7300000, "Bern", "23.3 ºc"} data(2) = New Object(3) {"France", 59500000, "Paris", "27.3 ºc"} data(3) = New Object(3) {"USA", 278000000, "Washington", "14.1 ºc"} data(4) = New Object(3) {"UK", 59700000, "London", "23.7 ºc"} data(5) = New Object(3) {"Belgium", 10300000, "Brussels", "21.8 ºc"} data(6) = New Object(3) {"Italy", 57700000, "Rome", "29.6 ºc"} data(7) = New Object(3) {"Spain", 40000000, "Madrid", "31.8 ºc"} data(8) = New Object(3) {"Germany", 83000000, "Berlin", "25.1 ºc"} data(9) = New Object(3) {"Japan", 126800000, "Tokyo", "17.2 ºc"} combo.DataSource = data combo.Location = New Point( 10 ,10 ) Me.Controls.Add( combo ) |
C# |
Copy Code |
---|---|
WinComboBox combo = new WinComboBox(); object[][] data = new object[ 10 ][] { new object[ 4 ] { "Canada" , 31500000 , "Ottawa" , "12.2 ºc" }, new object[ 4 ] { "Switzerland" , 7300000, "Bern" , "23.3 ºc"}, new object[ 4 ] { "France" , 59500000 , "Paris" , "27.3 ºc" } , new object[ 4 ] { "USA" , 278000000 , "Washington" , "14.1 ºc" } , new object[ 4 ] { "UK" , 59700000, "London" , "23.7 ºc" } , new object[ 4 ] { "Belgium" , 10300000, "Brussels" , "21.8 ºc" } , new object[ 4 ] { "Italy" , 57700000 , "Rome" , "29.6 ºc"} , new object[ 4 ] { "Spain" , 40000000 , "Madrid" , "31.8 ºc" } , new object[ 4 ] { "Germany" , 83000000, "Berlin" , "25.1 ºc" } , new object[ 4 ] { "Japan" , 126800000, "Tokyo" , "17.2 ºc" } }; combo.DataSource = data; combo.Location = new Point( 10, 10 ); this.Controls.Add( combo ); |
In the case where the WinComboBox control is created using the constructor that accepts a DisplayFormat, only the columns specified by the DisplayFormat and ValueMember parameters will be created in the DropDownControl.