New to Telerik UI for WinFormsStart a free 30-day trial

Using Custom Editors

Updated over 6 months ago

Most of the grid editors inherit from BaseVirtualGridEditor. The following steps and code snippet demonstrate how to replace the standard editor with a custom one containing a RadMultiColumnComboBoxElement:

  1. Create a class that inherits BaseVirtualGridEditor.

  2. Override its CreateEditorElement method and return a new instance of RadMultiColumnComboBoxElement.

  3. Introduce DataSource, ValueMember, DisplayMember properties of the custom editor in order to data bind the editor element.

  4. Override the Value property and manage the editor's value considering the RadMultiColumnComboBoxElement.SelectedValue property.

  5. Subscribe to the RadVirtualGrid.EditorRequired event and replace the default editor for the desired column with your custom one.

    WinForms RadVirtualGrid Using Custom Editors

Creating MultiColumnComboBoxVirtualGridEditor

C#
public class MultiColumnComboBoxVirtualGridEditor : BaseVirtualGridEditor
{
    protected override Telerik.WinControls.RadElement CreateEditorElement()
    {
        return new RadMultiColumnComboBoxElement();
    }
    public override object Value
    {
        get
        {
            RadMultiColumnComboBoxElement editor = this.EditorElement as RadMultiColumnComboBoxElement;
            if (editor.SelectedValue != null)
            {
                if (!string.IsNullOrEmpty(editor.ValueMember))
                {
                    return editor.SelectedValue;
                }
            }
            return -1;
        }
        set
        {
            RadMultiColumnComboBoxElement editor = this.EditorElement as RadMultiColumnComboBoxElement;
            if (value == null)
            {
                editor.SelectedIndex = -1;
            }
            else if (editor.ValueMember != null)
            {
                editor.SelectedValue = value;
            }
        }
    }
    public object DataSource
    {
        get
        {
            RadMultiColumnComboBoxElement editorElement = this.EditorElement as RadMultiColumnComboBoxElement;
            return editorElement.DataSource;
        }
        set
        {
            RadMultiColumnComboBoxElement editorElement = this.EditorElement as RadMultiColumnComboBoxElement;
            if (editorElement.BindingContext == null)
            {
                editorElement.BindingContext = new BindingContext();
            }
            editorElement.DataSource = value;
        }
    }
    public string ValueMember
    {
        get
        {
            RadMultiColumnComboBoxElement editorElement = this.EditorElement as RadMultiColumnComboBoxElement;
            return editorElement.ValueMember;
        }
        set
        {
            RadMultiColumnComboBoxElement editorElement = this.EditorElement as RadMultiColumnComboBoxElement;
            editorElement.ValueMember = value;
        }
    }
    public string DisplayMember
    {
        get
        {
            RadMultiColumnComboBoxElement editorElement = this.EditorElement as RadMultiColumnComboBoxElement;
            return editorElement.DisplayMember;
        }
        set
        {
            RadMultiColumnComboBoxElement editorElement = this.EditorElement as RadMultiColumnComboBoxElement;
            editorElement.DisplayMember = value;
        }
    }
}
private void radVirtualGrid1_EditorRequired(object sender, Telerik.WinControls.UI.VirtualGridEditorRequiredEventArgs e)
{
    if (e.ColumnIndex == 2)
    {
        MultiColumnComboBoxVirtualGridEditor editor = new MultiColumnComboBoxVirtualGridEditor();
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(string));
        dt.Rows.Add(-1, "");
        for (int i = 0; i <= 9; i++)
        {
            dt.Rows.Add(i, "Item" + i);
        }
        editor.DataSource = dt;
        editor.ValueMember = "Id";
        editor.DisplayMember = "Name";
        e.Editor = editor;
    }
}

See Also

Virtual grid editors

In this article
See Also
Not finding the help you need?
Contact Support