Completed
Last Updated: 28 Nov 2014 06:56 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 24 Nov 2014 13:54
Category: GridView
Type: Bug Report
0
FIX. RadGridView - NullReferenceException when entering edit mode for GridViewMultiComboBoxColumn and the RadMultiColumnComboBoxElement .EditorControl.MasterTemplate.AutoGenerateColumns property is se
To reproduce:

public Form1()
{
    InitializeComponent();

    BindingSource bs1 = new BindingSource();
    BindingSource bs2 = new BindingSource();

    DataTable dt1 = new DataTable();
    dt1.Columns.Add("MortgageId", typeof(string));
    dt1.Columns.Add("MortgageNo", typeof(string));
    for (int i = 0; i < 50; i++)
    { 
        dt1.Rows.Add(i, Guid.NewGuid().ToString().Substring(0, 5));              
    }
    bs1.DataSource = dt1;

    DataTable dt2 = new DataTable();
    dt2.Columns.Add("PaymentCode", typeof(string));
    dt2.Columns.Add("Description", typeof(string));

    for (int i = 0; i < 50; i++)
    {
        dt2.Rows.Add(Guid.NewGuid().ToString().Substring(0, 5), Guid.NewGuid().ToString().Substring(0, 5));
    }
    bs2.DataSource = dt2;

    GridViewMultiComboBoxColumn col1 = new GridViewMultiComboBoxColumn("MortgageId");          
    col1.DataSource = bs1;
    col1.FieldName = "MortgageId";
    col1.DisplayMember = "MortgageId";
    col1.ValueMember = "MortgageId";
    col1.Width = 70;
    this.radGridView1.Columns.Add(col1);

    col1 = new GridViewMultiComboBoxColumn("PaymentCode");         
    col1.DataSource = bs2;
    col1.DisplayMember = "PaymentCode";
    col1.ValueMember = "PaymentCode";
    col1.FieldName = "PaymentCode";
    col1.Width = 70;
    this.radGridView1.Columns.Add(col1);

    this.radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized;
}

private void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
    if (e.Column.Name == "MortgageId")
    {
        RadMultiColumnComboBoxElement editor = e.ActiveEditor as RadMultiColumnComboBoxElement;
        if (editor != null)
        {
            editor.EditorControl.FilterDescriptors.Clear();
            editor.EditorControl.Columns.Clear();
            editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;
            editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("MortgageId"));
            editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("MortgageNo"));
            editor.DropDownWidth = 200;    
        }
        return;
    }
    if (e.Column.Name == "PaymentCode")
    {
        RadMultiColumnComboBoxElement editor = e.ActiveEditor as RadMultiColumnComboBoxElement;
        if (editor != null)
        {
            editor.EditorControl.FilterDescriptors.Clear();
            editor.EditorControl.Columns.Clear();
            editor.EditorControl.MasterTemplate.AutoGenerateColumns = false;
            editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("PaymentCode"));
            editor.EditorControl.Columns.Add(new GridViewTextBoxColumn("Description"));
            editor.DropDownWidth = 200;    
        }
        return;
    }
}


Workaround: do not set the RadMultiColumnComboBoxElement.EditorControl.MasterTemplate.AutoGenerateColumns property to false in the CellEditorInitialized event .
0 comments