New to Telerik UI for WinForms? Download free 30-day trial

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.

Figure 1: DataSource

WinForms RadMultiColumnComboBox DataSource

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.

Figure 2: DisplayMember and ValueMember

WinForms RadMultiColumnComboBox DisplayMember and ValueMember

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

Figure 3: Bound RadMultiColumnComboBox

WinForms RadMultiColumnComboBox Bound Mode

 Columns collection

You can set your own columns list using the Columns collection editor of RadGridView:

Figure 4: GridViewDataColumn Collection Editor

WinForms RadMultiColumnComboBox GridViewDataColumn Collection Editor

The collection editor is accessible through the Columns property in the Properties grid:

WinForms RadMultiColumnComboBox Columns

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


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"));
}

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


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

Me.RadMultiColumnComboBox1.DisplayMember = "LastName"
Me.RadMultiColumnComboBox1.ValueMember = "EmployeeID"
Me.RadMultiColumnComboBox1.DataSource = Me.EmployeesBindingSource

See Also

In this article