Data Binding in Windows Forms MultiColumn ComboBox

10 Oct 202214 minutes to read

Data binding concepts for the MultiColumnComboBox are discussed in the below topics.

DataView as data source

We can use the DataView as the DataSource for MultiColumnComboBox control. It can be done using the below code snippet.

private void Form1_Load(object sender, System.EventArgs e)
    //Create dataTable
    DataTable dt = new DataTable("Table1");

    // Create a Data Set
    DataSet ds = new DataSet();
    dt.Rows.Add(new string[] { "John", "Tina", "Doctor", "Italy" });
    dt.Rows.Add(new string[] { "Mary", "anu", "Teacher", "America" });
    dt.Rows.Add(new string[] { "asha", "roy", "Staff", "London" });
    dt.Rows.Add(new string[] { "George", "Gaskin", "Nurse", "germany" });
    dt.Rows.Add(new string[] { "sam", "jens", "Engineer", "Russia" });
    dt.Rows.Add(new string[] { "Ben", "Geo", "Developer", "India" });
    DataView view = new DataView(dt);

    this.MultiColumnComboBox1.DataSource = view;
    this.MultiColumnComboBox1.DisplayMember = "FirstName";
    this.MultiColumnComboBox1.ValueMember = "LastName";
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    'Create dataTable
    Dim dt As DataTable = New DataTable("Table1")

    ' Create a Data Set
    Dim ds As DataSet = New DataSet()
    dt.Rows.Add(New String() {"John", "Tina", "Doctor", "Italy"})
    dt.Rows.Add(New String() {"Mary", "anu", "Teacher", "America"})
    dt.Rows.Add(New String() {"asha", "roy", "Staff", "London"})
    dt.Rows.Add(New String() {"George", "Gaskin", "Nurse", "germany"})
    dt.Rows.Add(New String() {"sam", "jens", "Engineer", "Russia"})
    dt.Rows.Add(New String() {"Ben", "Geo", "Developer", "India"})
    Dim view As DataView = New DataView(dt)

    Me.MultiColumnComboBox1.DataSource = view
    Me.MultiColumnComboBox1.DisplayMember = "FirstName"
    Me.MultiColumnComboBox1.ValueMember = "LastName"
End Sub

DataView as data source

Using data adapter

This section deals with data binding in MultiColumnComboBox using OleDBDataAdapter. Follow the steps below.

  • Add a MultiColumnComboBox control to your form.
  • Add the appropriate DataAdapter and DataSets for your datasource.
  • Set the MultiColumnCombobox Datasource, DisplayMember and ValueMember properties.
  • Alternatively, you can set up the data binding in code, in the form’s load event handler as follows.
private void Form_Load(object sender, System.EventArgs e)
    // Fill the dataset.

    // Set the DataSource,DisplayMember,ValueMember properties.
    this.multiColumnComboBox1.DataSource = this.dataSet21.Customers;
    this.multiColumnComboBox1.DisplayMember = "ContactName";
    this.multiColumnComboBox1.ValueMember = "CompanyName";
Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    'Fill the dataset.

    ' Set the DataSource,DisplayMember,ValueMember properties.
    Me.multiColumnComboBox1.DataSource = Me.dataSet21.Customers
    Me.multiColumnComboBox1.DisplayMember = "ContactName"
    Me.multiColumnComboBox1.ValueMember = "CompanyName"
End Sub

A sample which demonstrates the OleDbDataAdapter data binding is available in the below sample installation location.

…_My Documents\Syncfusion\EssentialStudio\Version Number\Windows\Tools.Windows\Samples\Advanced Editor Functions\ActionGroupingDemo_

Populating MultiColumnComboBox

This section deals with populating MultiColumnComboBox with typed Dataset as datasource. Follow the steps below :

  1. Open VS .NET IDE and click File -> New -> Project -> Windows Application.
  2. Right click the project in the Solutions Explorer and click Add -> New Item and Add New Item dialog box will be displayed.
  3. Select DataSet from templates pane, give the name (Say new dataset.XSD) and click Open. This will add file by name new dataset.XSD to the solution.
  4. Add the XML Schema as shown below.

    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:EnforceConstraints="False">
            <xs:choice maxOccurs="unbounded">
                <xs:element name="roster">
                            <xs:element name="PositionID" type="xs:string" minOccurs="0" />
                            <xs:element name="EmployeeID" type="xs:string" minOccurs="0" />
                            <xs:element name="PersonID" type="xs:string" minOccurs="0" />
                            <xs:element name="FirstName" type="xs:string" minOccurs="0" />
                            <xs:element name="LastName" type="xs:string" minOccurs="0" />
                            <xs:element name="BizUnitName" type="xs:string" minOccurs="0" />
                            <xs:element name="Title" type="xs:string" minOccurs="0" />
                            <xs:element name="FunctionalTitle" type="xs:string" minOccurs="0" />
                            <xs:element name="CorporateID" type="xs:string" minOccurs="0" />
                            <xs:element name="UserID" type="xs:int" minOccurs="0" />
  5. Validate the written Schema.
  6. Add an XML file (Say new dataset.xml) with the following data.

    <?xml version="1.0" standalone="yes" ?>
    <NewDataSet xmlns="">
  7. Write a method to load data from XML file.

    // Loads data from XML file.
    private void LoadFromFile(string fileName)
    	string remString = "\\bin\\debug";
    	string path = Application.StartupPath.Remove(Application.StartupPath.Length - remString.Length, remString.Length)+ "\\" + fileName;
    	NewDataSet newDataSet1 = new NewDataSet();
    	userCmbBox.DataSource =  newDataSet1.Tables [0];
    	serCmbBox.DisplayMember = newDataSet1.roster.LastNameColumn.ColumnName;
    	userCmbBox.ValueMember = newDataSet1.roster.EmployeeIDColumn.ColumnName;
    	this.userCmbBox.ListBox.Grid.Model.Cols.Hidden[newDataSet1.roster.PersonIDColumn.ColumnName] = true;
    	this.userCmbBox.ListBox.Grid.Model.Cols.Hidden[newDataSet1.roster.UserIDColumn.ColumnName] = true;
    	this.userCmbBox.ListBox.Grid.Model.Cols.Hidden[newDataSet1.roster.EmployeeIDColumn.ColumnName] = true;
    	this.userCmbBox.ListBox.Grid.Model.Cols.Hidden[newDataSet1.roster.PositionIDColumn.ColumnName] = true;
    'Loads data from XML file.
    Private Sub LoadFromFile(ByVal fileName As String)
        Dim remString As String = "\bin\debug"
        Dim path As String = Application.StartupPath.Remove(Application.StartupPath.Length - remString.Length, remString.Length) + "\" & fileName
        Dim newDataSet1 As NewDataSet = New NewDataSet()
        userCmbBox.DataSource = newDataSet1.Tables(0)
        serCmbBox.DisplayMember = newDataSet1.roster.LastNameColumn.ColumnName
        userCmbBox.ValueMember = newDataSet1.roster.EmployeeIDColumn.ColumnName
        Me.userCmbBox.ListBox.Grid.Model.Cols.Hidden(newDataSet1.roster.PersonIDColumn.ColumnName) = True
        Me.userCmbBox.ListBox.Grid.Model.Cols.Hidden(newDataSet1.roster.UserIDColumn.ColumnName) = True
        Me.userCmbBox.ListBox.Grid.Model.Cols.Hidden(newDataSet1.roster.EmployeeIDColumn.ColumnName) = True
        Me.userCmbBox.ListBox.Grid.Model.Cols.Hidden(newDataSet1.roster.PositionIDColumn.ColumnName) = True
    End Sub
  8. Load the values in the Form’s Load event.

    private void Form1_Load(object sender, System.EventArgs e)
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    End Sub

Populating MultiColumnComboBox

See Also

How to load MultiColumnComboBox dropdown items in on-demand?