Xceed Grid for WinForms v4.3 Documentation
DataSource Property (WinComboBox)
Example 


Xceed.Grid.v4.3 Assembly > Xceed.Editors Namespace > WinComboBox Class : DataSource Property
Gets or sets the data source used to populate the combobox.
Syntax
'Declaration
 
<DescriptionAttribute("The data source used to populate the combobox.")>
<CategoryAttribute("Data")>
<DefaultValueAttribute("")>
Public Property DataSource As Object
'Usage
 
Dim instance As WinComboBox
Dim value As Object
 
instance.DataSource = value
 
value = instance.DataSource
[Description("The data source used to populate the combobox.")]
[Category("Data")]
[DefaultValue("")]
public object DataSource {get; set;}

Property Value

A reference to an object representing the data source to use to populate the combobox.
Remarks

If the DataSource contains more than one table, you must set the DataMember property to a string that represents the name of the table to bind to.

The following is a list of the supported data sources:

System.Data.DataTable Represents one table of in-memory data.
System.Data.DataView Represents a databindable, customized view of a System.Data.DataTable for sorting, filtering, searching, editing, and navigation.
System.Data.DataSet Represents an in-memory cache of data.
System.Data.DataViewManager Contains a default System.Data.DataViewSettingCollection for each System.Data.DataTable in a System.Data.DataSet.
Any component that implements the System.ComponentModel.IListSource interface. Provides functionality to an object to return a list that can be bound to a data source.
Any component that implements the System.Collections.IList interface. Represents a collection of objects that can be individually accessed by index.
Jagged arrays A jagged array is an array whose elements are arrays.

If the data source is a jagged array and 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.
Example

The next example demonstrates how to bind the combobox to a jagged array:

Imports Xceed.Editors
Imports System.Data.OleDb

Dim connectionString As String = "" 'connection query
Dim connection As New OleDbConnection( connectionString )

connection.Open()

Dim selectQuery As String = "SELECT * FROM Clients"
Dim dataAdapter As New OleDbDataAdapter( selectQuery, connection )
Dim dataSet As New DataSet( "Clients" )

dataAdapter.Fill( dataSet )

Dim combo As New WinComboBox

combo.Location = New Point(10, 10)
Me.Controls.Add(combo)

combo.DataSource = dataSet.Tables( 0 )
using Xceed.Editors;
using System.Data.OleDb;

string connectionString = ""; //connection query
OleDbConnection connection = new OleDbConnection( connectionString );

connection.Open();

string selectQuery = "SELECT * FROM Clients";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter( selectQuery, connection );
DataSet dataSet = new DataSet( "Clients" );

dataAdapter.Fill( dataSet );

WinComboBox combo = new WinComboBox();

combo.Location = new Point( 10, 10 );
this.Controls.Add( combo );

combo.DataSource = dataSet.Tables[ 0 ];
' Create a jagged array
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"}
     
Dim combo As New WinComboBox()

combo.Location = New Point( 10 ,10 )
Me.Controls.Add( combo )     
 
' Assign the jagged array to the DataSource property
combo.DataSource = data
// Create a jagged array
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" } };
                                  
WinComboBox combo = new WinComboBox();

combo.Location = new Point( 10, 10 );
this.Controls.Add( combo );

// Assign the jagged array to the DataSource property                            
combo.DataSource = data;
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

WinComboBox Class
WinComboBox Members