Item Contains

3 posts, 1 answers
  1. Chris
    Chris avatar
    4 posts
    Member since:
    Nov 2012

    Posted 08 Nov 2012 Link to this post

    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?

  2. Answer
    Stefan avatar
    2890 posts

    Posted 13 Nov 2012 Link to this post

    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,
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Chris
    Chris avatar
    4 posts
    Member since:
    Nov 2012

    Posted 14 Nov 2012 Link to this post

    Thanks, i did end up just iterating through the items collection.
Back to Top