Completed
Last Updated: 05 May 2016 12:29 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 17 Mar 2016 12:58
Category: GridView
Type: Bug Report
1
FIX. RadGridView - ArgumentException in Excel-like filtering with null and empty (blanks) values
To reproduce: use the following code snippet. From the filtering box, when you select "Null" and then select "All", the following error occurs:
Item has already been added. Key in dictionary: '(Blanks)'  Key being added: '(Blanks)'

DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));

dt.Rows.Add(1,"A");
dt.Rows.Add(2, "");
dt.Rows.Add(3, null);
dt.Rows.Add(4, "B");
dt.Rows.Add(5, "C");
dt.Rows.Add(6, "");
this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.EnableFiltering = true;
this.radGridView1.ShowFilteringRow = false;
this.radGridView1.ShowHeaderCellButtons = true;

Workaround:  this.radGridView1.FilterPopupInitialized += radGridView1_FilterPopupInitialized;

RadListFilterDistinctValuesTable selectedValues;

private void radGridView1_FilterPopupInitialized(object sender, Telerik.WinControls.UI.FilterPopupInitializedEventArgs e)
{
    RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup;
    selectedValues = popup.MenuTreeElement.SelectedValues;
    popup.MenuTreeElement.TreeView.NodeCheckedChanged += TreeView_NodeCheckedChanged;
}

private void TreeView_NodeCheckedChanged(object sender, TreeNodeCheckedEventArgs e)
{
    if (e.Node.CheckState == Telerik.WinControls.Enumerations.ToggleState.Off)
    {
        if (selectedValues.Contains(e.Node.Text))
        {
            selectedValues.Remove(e.Node.Text);
        }
    }
}
0 comments