How to get data from RadListView (Type: DetailsView)

1 Answer 479 Views
ListView
Hoang
Top achievements
Rank 1
Hoang asked on 05 Aug 2021, 04:26 PM
I don't know how to get data from each column in RadListView. How to get data from first column?
Thanks for reading!

1 Answer, 1 is accepted

Sort by
1
Accepted
Nadya | Tech Support Engineer
Telerik team
answered on 06 Aug 2021, 02:38 PM

Hello, Hoang,

RadListView in DetailsView provides a grid-like interface for displaying items. If you want to get the cell values from the first column you can use the following code snippet:

foreach (ListViewDataItem item in this.radListView1.Items)
{
    Console.WriteLine(item[0]);
}

I hope this helps. Let me know if you have any other questions.

Regards,
Nadya
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Hoang
Top achievements
Rank 1
commented on 07 Aug 2021, 12:30 PM

Thanks for your help, that works!  But how to get data from 1 selected column?
Hoang
Top achievements
Rank 1
commented on 07 Aug 2021, 03:50 PM

I have another question that I hope you can answer. How to bulk delete items containing certain characters in ListView?

Here is my code:


  foreach( var item in radListView1.Items)
            {
                if (item[1].ToString() == "Gas")
                    radListView1.Items.Remove(item);
            }

Get Error message:  Collection was modified; enumeration operation may not execute.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 09 Aug 2021, 01:13 PM

Hello, Hoang,

You can get cell values to the items of RadListView using their indexers. The keys can be either the index of the column, the name of the column, or the column itself. In the previous code snippet, provided by Nadya, item[0] means that the cell's value of the very first column will be extracted. Changing the index from 0 to 1 and so on, you will get the value of the next column. The following article demonstrates how to add columns to RadListView and specify values to these cells. In a similar way you can extract the cell's value: https://docs.telerik.com/devtools/winforms/controls/listview/populating-with-data/unbound-mode#adding-columns 

As to the error message, it seems that you are removing an item from the collection while the collection itself is being iterated. After some research in general programming forums, I have found the following article which is quite useful on this topic:
https://makolyte.com/system-invalidoperationexception-collection-was-modified-enumeration-operation-may-not-execute/ 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 
Hoang
Top achievements
Rank 1
commented on 10 Aug 2021, 12:44 AM

Thanks you!
Tags
ListView
Asked by
Hoang
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or