This is a migrated thread and some comments may be shown as answers.

Can't add ListViewDataItem after Column Sort

2 Answers 134 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Brandon
Top achievements
Rank 1
Brandon asked on 26 Mar 2012, 10:03 PM
I have enabled Sorting and Column Sorting under the Telerik ListView properties.

This ListView is updated on a regular interval. In the update method I call Items.Clear() and Columns.Clear().
I add some columns programmitically as well. However, when the code runs below it throws an "Out of range index" exception.

radListView.Items.Add(new ListViewDataItem(dr["Mon"].ToString() + dr["Year"].ToString()));
ListViewDataItem item = this.radListView.Items[0];

This only occurs after I have clicked a column header to sort it. If the column was not sorted, the code runs fine.
When I look at the Count of radListView.Items the Count is 0. This means the radListView.Item.Add method did nothing..

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 30 Mar 2012, 08:49 AM
Hi Brandon,

Thank you for contacting us.

Despite my efforts I was not able to reproduce this exception. Generally, after you have added an item to the Items collection, it will not appear in it if the filtering is enabled and you have added a filter rule that excludes this item (the item will appear later when you either disable filtering or change the filter descriptors). However, I am not sure if this is the case since the code you have provided is not sufficient. Therefore, I would kindly ask you to open a new support ticket and send me a sample project which demonstrates the exception. Alternatively, you can post the full source code of the sample project here in this thread. This will let me investigate the scenario and provide you with adequate support.

I am looking forward to hearing from you.

Greetings,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Brandon
Top achievements
Rank 1
answered on 02 Apr 2012, 02:22 PM
Ivan was able to help with this when I submitted a support ticket. Below is the answer.
ListViewDataItem item = new ListViewDataItem(dr["TP_MON"].ToString() + dr["TP_Year"].ToString());
radlistview.Items.Add(item);
Tags
ListView
Asked by
Brandon
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Brandon
Top achievements
Rank 1
Share this question
or