Completed
Last Updated: 21 Oct 2015 11:15 by ADMIN
ADMIN
Dimitar
Created on: 29 Sep 2015 10:52
Category: GridView
Type: Bug Report
0
FIX. RadGridView - StackOverflow exception when excel-like filtering is used with more than 12 000 unique items.
To reproduce:
public RadForm1()
{
    InitializeComponent();
    Controls.Add(new RadGridView
    {
        Dock = DockStyle.Fill,
        ShowHeaderCellButtons = true,
        ReadOnly = true,
        AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill,
        EnableFiltering = true,
        DataSource = Enumerable.Range(0, 24000) //Increase this number when you can't reproduce this issue
        .Select(x => new { Name = string.Format("Item {0}", x) }),
    });
}

Workaround:
class MyListFillter : RadListFilterPopup
{
    public MyListFillter(GridViewDataColumn column, bool groupDateValues) : base(column, groupDateValues)
    {
    }

    protected override void OnButtonOkClick(EventArgs e)
    {
        FilterOperator filterOperator = FilterOperator.IsEqualTo;
        var listFilterElement = typeof(RadListFilterPopup).GetField("listFilterElement", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this) as FilterMenuTreeElement;

        switch (listFilterElement.SelectedMode)
        {
            case ListFilterSelectedMode.All:
                filterOperator = FilterOperator.None;
                break;
            case ListFilterSelectedMode.Null:
                filterOperator = FilterOperator.IsNull;
                break;
            case ListFilterSelectedMode.NotNull:
                filterOperator = FilterOperator.IsNotNull;
                break;
        }

        if (filterOperator != FilterOperator.IsEqualTo)
        {
            SetFilterOperator(filterOperator);
            this.ClosePopup(RadPopupCloseReason.CloseCalled);
        }
        else
        {
            CompositeFilterDescriptor compositeFilterDescriptor = new CompositeFilterDescriptor();
            compositeFilterDescriptor.PropertyName = base.DataColumn.Name;
            compositeFilterDescriptor.LogicalOperator = FilterLogicalOperator.Or;
           
            if (listFilterElement.SelectedValues.Count > this.GetDistinctValuesTable().Count / 2)
            {                    
                foreach (DictionaryEntry entry in this.GetDistinctValuesTable())
                {
                    if (!listFilterElement.SelectedValues.Contains(entry.Key))
                    {
                        foreach (object value in (ArrayList)entry.Value)
                        {
                            FilterDescriptor descriptor;
                            if (base.DataColumn is GridViewDateTimeColumn || base.DataColumn.DataType == typeof(DateTime) ||
                                base.DataColumn.DataType == typeof(DateTime?))
                            {
                                descriptor = new DateFilterDescriptor(base.DataColumn.Name, FilterOperator.IsNotEqualTo, (DateTime?)value, false);
                            }
                            else
                            {
                                descriptor = new FilterDescriptor(base.DataColumn.Name, FilterOperator.IsNotEqualTo, value);
                            }
                            compositeFilterDescriptor.FilterDescriptors.Add(descriptor);
                        }
                    }
                }
            }
            else
            {
                foreach (DictionaryEntry entry in listFilterElement.SelectedValues)
                {
                    foreach (object value in (ArrayList)entry.Value)
                    {
                        FilterDescriptor descriptor;
                        if (base.DataColumn is GridViewDateTimeColumn || base.DataColumn.DataType == typeof(DateTime) ||
                            base.DataColumn.DataType == typeof(DateTime?))
                        {
                            descriptor = new DateFilterDescriptor(base.DataColumn.Name, FilterOperator.IsEqualTo, (DateTime?)value, false);
                        }
                        else
                        {
                            descriptor = new FilterDescriptor(base.DataColumn.Name, FilterOperator.IsEqualTo, value);
                        }
                        compositeFilterDescriptor.FilterDescriptors.Add(descriptor);
                    }
                }
            }
            base.FilterDescriptor = compositeFilterDescriptor;
            OnFilterConfirmed();
        }
    }
}
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments