Completed
Last Updated: 10 Sep 2015 08:34 by ADMIN
ADMIN
Hristo
Created on: 09 Jul 2015 08:25
Category: ListView, CardView and CheckedListBox
Type: Bug Report
1
FIX. RadListView - having more than 10000 items with a SortDescriptor results in a NullReferenceException, because RadListView.CurrentItem is null
How to reproduce:

public partial class RadForm1 : RadForm
{
    public RadForm1()
    {
        InitializeComponent();

        var __listViewDetailColumnName = new ListViewDetailColumn("columnHeader_name", "Name");
        var __listViewDetailColumnType = new ListViewDetailColumn("columnHeader_type", "Type");
        var __listViewDetailColumnDescription = new ListViewDetailColumn("columnHeader_description", "Description")
        {
            Width = 281F
        };

        this.listView1.Columns.AddRange(new[] {
        __listViewDetailColumnName,
        __listViewDetailColumnType,
        __listViewDetailColumnDescription});

        this.listView1.AllowEdit = false;
        this.listView1.AllowRemove = false;
        this.listView1.EnableColumnSort = true;
        this.listView1.EnableSorting = true;
        this.listView1.HeaderHeight = 25F;
        this.listView1.ItemSpacing = -1;
        this.listView1.KeyboardSearchEnabled = true; this.listView1.SelectLastAddedItem = false;
        this.listView1.ShowGridLines = true;
        var __sortDescriptor1 = new Telerik.WinControls.Data.SortDescriptor
        {
            PropertyName = __listViewDetailColumnName.Name,
            Direction = ListSortDirection.Ascending
        };
        this.listView1.SortDescriptors.AddRange(new[] { __sortDescriptor1 });
        this.listView1.ViewType = ListViewType.DetailsView;
    }

    private void buttonClose_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void buttonPopulateOk_Click(object sender, EventArgs e)
    {
        this.Populate(10000);
    }

    private void buttonPopulateError_Click(object sender, EventArgs e)
    {
        this.Populate(10001);
    }

    private void Populate(int count)
    {
        this.listView1.BeginUpdate();

        this.listView1.Items.Clear();

        for (var __i = 1; __i <= count; __i++)
        {
            var __name = String.Format(@"Item-{0:D5}", __i);
            var __type = String.Format(@"Type-{0:D5}", __i);
            var __description = String.Format(@"Description-{0:D5}", __i);

            var __item = new ListViewDataItem(__name);
            __item.SubItems.Add(__name);
            __item.SubItems.Add(__type);
            __item.SubItems.Add(__description);

            this.listView1.Items.Add(__item);
        }

        this.listView1.EndUpdate();

    }
}


Workaround: after the addition of the items, set the current item and then add the sort descriptor

public partial class RadForm1 : RadForm
{
    ListViewDetailColumn __listViewDetailColumnName;

    public RadForm1()
    {
        InitializeComponent();

        __listViewDetailColumnName = new ListViewDetailColumn("columnHeader_name", "Name");
        var __listViewDetailColumnType = new ListViewDetailColumn("columnHeader_type", "Type");
        var __listViewDetailColumnDescription = new ListViewDetailColumn("columnHeader_description", "Descripti
        {
            Width = 281F
        };

        this.listView1.Columns.AddRange(new[] {
        __listViewDetailColumnName,
        __listViewDetailColumnType,
        __listViewDetailColumnDescription});

        this.listView1.AllowEdit = false;
        this.listView1.AllowRemove = false;
        this.listView1.EnableColumnSort = true;
        this.listView1.EnableSorting = true;
        this.listView1.HeaderHeight = 25F;
        this.listView1.ItemSpacing = -1;
        this.listView1.KeyboardSearchEnabled = true; this.listView1.SelectLastAddedItem = false;
        this.listView1.ShowGridLines = true;
        this.listView1.ViewType = ListViewType.DetailsView;
    }

    private void buttonClose_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void buttonPopulateOk_Click(object sender, EventArgs e)
    {
        this.Populate(10000);
    }

    private void buttonPopulateError_Click(object sender, EventArgs e)
    {
        this.Populate(10001);
    }

    private void Populate(int count)
    {
        this.listView1.BeginUpdate();
        this.listView1.Items.Clear();

        for (var __i = 1; __i <= count; __i++)
        {
            var __name = String.Format(@"Item-{0:D5}", __i);
            var __type = String.Format(@"Type-{0:D5}", __i);
            var __description = String.Format(@"Description-{0:D5}", __i);

            var __item = new ListViewDataItem(__name);
            __item.SubItems.Add(__name);
            __item.SubItems.Add(__type);
            __item.SubItems.Add(__description);

            this.listView1.Items.Add(__item);
        }

        this.listView1.EndUpdate();

        this.listView1.CurrentItem = this.listView1.Items[0];
        var __sortDescriptor1 = new Telerik.WinControls.Data.SortDescriptor
        {
            PropertyName = __listViewDetailColumnName.Name,
            Direction = ListSortDirection.Ascending
        };
        this.listView1.SortDescriptors.AddRange(new[] { __sortDescriptor1 });
        this.listView1.CurrentItem = null;
    }
}
0 comments