MultiColumnCombo for WinForms | ComponentOne
In This Topic
    Data Binding
    In This Topic

    MultiColumnCombo supports bound and unbound modes to display data. In bound mode, you can bind the MultiColumnCombo control to a data source to populate data in it, while in unbound mode, you can manually populate the control with data. Let us discuss how to bind data in bound and unbound modes in detail in the following sections.

    Bound Mode

    Bound mode, as the name suggests, refers to a state where control fetches its data from an underlying data source. MultiColumnCombo can be bound to commonly used data sources such as ObservableCollection, IBindingListView, IList <T>, List<T>, etc.

    MultiColumnCombo control in bound mode

    To bind the MultiColumnCombo control to data, you need to set the data source object using DataSource property of the C1MultiColumnCombo class as showcased in the following code. In addition to the DataSource property, you also need to set the DisplayMember and ValueMember properties of the C1MultiColumnCombo class when binding the MultiColumnCombo control to the data in bound mode. The DisplayMember property sets the DataSource field to display as text of the control and the ValueMember specifies the field name as value for binding purposes. The following example uses DataSource class to get the data.

    C#
    Copy Code
    var data = new BindingSource(DataSource.GetSalesInfo(), "");
    
    mcc.DataSource = data;
    mcc.DisplayMember = "Product";
    mcc.ValueMember = "Id";
    

    Back to top

    Unbound Mode

    As the name suggests, in unbound mode, MultiColumnCombo control is not bound to any data source and data is stored in the control itself. In this case, you need to provide data by adding rows and/or columns either at design time or programmatically.

    MultiColumnCombo control in unbound mode

    To provide data to MultiColumnCombo in unbound mode, first you need to add columns to the control using the Add method and then add items in the control using the AddItem method as shown in the following code. In MultiColumnCombo, the columns in the dropdown view are represented by DisplayColumn class. This class provides all the properties that are specific to the columns, for example, Name and Caption properties. When you add columns in MultiColumnCombo, you need to set the Name and Caption properties for the column being added. The following example uses Customer class to get the data for the control.

    C#
    Copy Code
    C1.Win.Input.MultiColumnCombo.DisplayColumn displayColumn1 = new C1.Win.Input.MultiColumnCombo.DisplayColumn();
    C1.Win.Input.MultiColumnCombo.DisplayColumn displayColumn2 = new C1.Win.Input.MultiColumnCombo.DisplayColumn();
    
    displayColumn1.Caption = "Name";
    displayColumn1.Name = "Name";
    displayColumn2.Caption = "Capital";
    displayColumn2.Name = "Capital";
                
    mcc.Columns.Add(displayColumn1);
    mcc.Columns.Add(displayColumn2);
    
    mcc.AddItem(Country.GetCountry(0).ToString());
    mcc.AddItem(Country.GetCountry(1).ToString());
    mcc.AddItem(Country.GetCountry(2).ToString());
    mcc.AddItem(Country.GetCountry(3).ToString());
    mcc.AddItem(Country.GetCountry(4).ToString());
    

    Back to top