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

Item Contains

2 Answers 39 Views
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 08 Nov 2012, 10:17 PM
There is a Contains method for the items collection that checks for a ListViewDataItem, however I want to check for the existance of a specific value. I want to insert a new item into the listview but only if a certain value does not exist in one of the columns. Is there any built in functionality for this? Or do i have to iterate through the items collection myself and compare against that column value?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 13 Nov 2012, 10:36 AM
Hello Chris,

Thank you for writing.

Currently, the only possible way to achieve what you want is to iterate the items and make the comparison yourself. Alternatively, if you are using .NET3.5 or above, you can use LINQ:
List<ListViewDataItem> contains = radListView1.Items.Where(x => object.Equals(x[0],"Row 2") || object.Equals(x[1],"Row 2")).ToList();
          if (contains.Count > 0)
          {
              //the item exists in the collection
          }

I hope this helps.
 
Kind regards,
Stefan
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Chris
Top achievements
Rank 1
answered on 15 Nov 2012, 02:22 AM
Thanks, i did end up just iterating through the items collection.
Asked by
Chris
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Chris
Top achievements
Rank 1
Share this question
or