# Data Binding

Data binding is a mechanism for automatic population of the **RadMultiColumnComboBox** with data, based on the provided data structure. Three properties control the data binding:

* **DataSource** - specifies the data structure to be bound.

* **DisplayMember** - specifies the particular field in the data source which will be used from the items in **RadMultiColumnComboBox** for the Text.

* **ValueMember** - specifies the particular field in the data source which will be stored in the Value property.

**RadMultiColumnComboBox** supports data binding either at design time or at run time:

## Data Binding at design time

You can set the **DataSource** property at design time in the *Properties* window of Visual Studio.

1\. Select the **DataSource** property and click the drop-down arrow to display all existing data sources on the form.

> caption Figure 1: DataSource

![WinForms RadMultiColumnComboBox DataSource](https://www.telerik.com/products/winforms/documentation/assets/b9aca3b70c929157820b2eeda8d7ec62/multicolumncombobox-databinding001.png)

This will force the **RadGridView** (contained in **RadMultiColumnComboBox**) to auto-generate columns for each field in the specified **DataSource**. 

2\. Set the **DisplayMember** and **ValueMember** properties.

> caption Figure 2: DisplayMember and ValueMember

![WinForms RadMultiColumnComboBox DisplayMember and ValueMember](https://www.telerik.com/products/winforms/documentation/assets/4443c18b858bfdcef58813b089cfa0eb/multicolumncombobox-databinding002.png)

As a result **RadMultiColumnComboBox** is bound to the Northwind.Customers table:

> caption Figure 3: Bound RadMultiColumnComboBox

![WinForms RadMultiColumnComboBox Bound Mode](https://www.telerik.com/products/winforms/documentation/assets/4356cdbddaacf1054f2eaba0c7b55aa7/multicolumncombobox-databinding003.png)

###  Columns collection

You can set your own columns list using the [Columns](https://docs.telerik.com/devtools/winforms/controls/gridview/columns/gridviewcolumn) collection editor of **RadGridView**:

> caption Figure 4: GridViewDataColumn Collection Editor

![WinForms RadMultiColumnComboBox GridViewDataColumn Collection Editor](https://www.telerik.com/products/winforms/documentation/assets/cab3eaaeb78453678b098270524b085c/multicolumncombobox-databinding004.png)

The collection editor is accessible through the [Columns](https://docs.telerik.com/devtools/winforms/controls/gridview/columns/gridviewcolumn) property in the *Properties* grid:

![WinForms RadMultiColumnComboBox Columns](https://www.telerik.com/products/winforms/documentation/assets/af13f2f3d0fd05954d244b7654a2ccaf/multicolumncombobox-databinding005.png)

The important point when adding columns manually is to turn off the automatic generation of columns, otherwise you will have your columns duplicated in run time.

#### Adding columns

```C#
protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    
    NwindDataSet nwindDataSet = new NwindDataSet();
    CustomersTableAdapter customersTableAdapter = new CustomersTableAdapter();
    customersTableAdapter.Fill(nwindDataSet.Customers);
    this.radMultiColumnComboBox1.DataSource = nwindDataSet.Customers;
    foreach (GridViewDataColumn column in
        this.radMultiColumnComboBox1.MultiColumnComboBoxElement.Columns)
    {
        column.BestFit();
    }
}
    
void SetUpGrid()
{
    RadGridView gridViewControl = this.radMultiColumnComboBox1.EditorControl;
    gridViewControl.MasterTemplate.AutoGenerateColumns = false;
    gridViewControl.Columns.Add(new GridViewTextBoxColumn("CustomerID"));
    gridViewControl.Columns.Add(new GridViewTextBoxColumn("ContactName"));
    gridViewControl.Columns.Add(new GridViewTextBoxColumn("ContactTitle"));
    gridViewControl.Columns.Add(new GridViewTextBoxColumn("Country"));
    gridViewControl.Columns.Add(new GridViewTextBoxColumn("Phone"));
}
    
```

```VB.NET
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
    MyBase.OnLoad(e)

    Dim nwindDataSet As New NwindDataSet()
    Dim customersTableAdapter As New CustomersTableAdapter()
    customersTableAdapter.Fill(nwindDataSet.Customers)
    Me.RadMultiColumnComboBox1.DataSource = nwindDataSet.Customers
    For Each column As GridViewDataColumn In Me.RadMultiColumnComboBox1.MultiColumnComboBoxElement.Columns
        column.BestFit()
    Next column
End Sub

Private Sub SetUpGrid()
    Dim gridViewControl As RadGridView = Me.RadMultiColumnComboBox1.EditorControl
    gridViewControl.MasterTemplate.AutoGenerateColumns = False
    gridViewControl.Columns.Add(New GridViewTextBoxColumn("CustomerID"))
    gridViewControl.Columns.Add(New GridViewTextBoxColumn("ContactName"))
    gridViewControl.Columns.Add(New GridViewTextBoxColumn("ContactTitle"))
    gridViewControl.Columns.Add(New GridViewTextBoxColumn("Country"))
    gridViewControl.Columns.Add(New GridViewTextBoxColumn("Phone"))
End Sub
```

## Data binding at run time

You can bind **RadMultiColumnComboBox** programmatically. It is necessary to set the **DataSource**, **ValueMember** and **DisplayMember** properties of **RadMultiColumnComboBox**.

#### Binding at run time

```C#
this.radMultiColumnComboBox1.DisplayMember = "LastName";
this.radMultiColumnComboBox1.ValueMember = "EmployeeID";
this.radMultiColumnComboBox1.DataSource = this.employeesBindingSource;

```

```VB.NET
Me.RadMultiColumnComboBox1.DisplayMember = "LastName"
Me.RadMultiColumnComboBox1.ValueMember = "EmployeeID"
Me.RadMultiColumnComboBox1.DataSource = Me.EmployeesBindingSource

```

## See Also

* [Unbound Mode](https://www.telerik.com/products/winforms/documentation/controls/multicolumncombobox/populating-with-data/unbound-mode)
