RadControls for WinForms

This column has RadMultiColumnComboBoxElement as an editor. It covers the features that the RadMultiColumnComboBox control has.

The following example demonstrates how to manually generate columns for RadGridView in the dropdown and then make the dropdown autosize itself according to the width of the RadGridView columns.

 

First of all, we should bind the GridViewMultiComboBoxColumn:

Copy[C#] Creating and setting up GridViewMultiComboBoxColumn
GridViewMultiComboBoxColumn col = new GridViewMultiComboBoxColumn();
col.DataSource = orderDetailsBindingSource;
col.DisplayMember = "Quantity";
col.ValueMember = "OrderID";
col.FieldName = "OrderID";
col.HeaderText = "Custom";
this.radGridView1.Columns.Add(col);
this.radGridView1.CellBeginEdit += new GridViewCellCancelEventHandler(radGridView1_CellBeginEdit);
Copy[VB.NET] Creating and setting up GridViewMultiComboBoxColumn
Dim col As GridViewMultiComboBoxColumn = New GridViewMultiComboBoxColumn()
col.DataSource = orderDetailsBindingSource
col.DisplayMember = "Quantity"
col.ValueMember = "OrderID"
col.FieldName = "OrderID"
col.HeaderText = "Custom"
Me.RadGridView1.Columns.Add(col)
AddHandler RadGridView1.CellBeginEdit, AddressOf radGridView1_CellBeginEdit

Then, we make the necessary implementation in the CellBeginEdit event handler:

Copy[C#] Setup the editor
bool isColumnAdded;
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    if (this.radGridView1.CurrentColumn is GridViewMultiComboBoxColumn)
    {
        if (!isColumnAdded)
        {
            isColumnAdded = true;
            RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)this.radGridView1.ActiveEditor;
            editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;
            editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("OrderID"));
            editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("Quantity"));
            editor.AutoSizeDropDownToBestFit = true;
        }
    }
}
Copy[VB.NET] Setup the editor
Private isColumnAdded As Boolean
Private Sub radGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As GridViewCellCancelEventArgs)
    If TypeOf Me.radGridView1.CurrentColumn Is GridViewMultiComboBoxColumn Then
        If (Not isColumnAdded) Then
            isColumnAdded = True
            Dim editor As RadMultiColumnComboBoxElement = CType(Me.radGridView1.ActiveEditor, RadMultiColumnComboBoxElement)
            editor.EditorControl.MasterTemplate.AutoGenerateColumns = False
            editor.EditorControl.Columns.Add(New GridViewTextBoxColumn("OrderID"))
            editor.EditorControl.Columns.Add(New GridViewTextBoxColumn("Quantity"))
            editor.AutoSizeDropDownToBestFit = True
        End If
    End If
End Sub

Please note that we have a 'dirty' flag, because the editors in RadGridView are reused. If we do not have such a flag, new OrderID and Quantity columns will be added each time a RadMultiColumnComboBoxElement editor is opened.