c# - ListView CheckedItems find item by name -
i need check if item particular name exists in checkeditems collection of listview.
so far i've tried:
listviewitem item = new listviewitem(itemname); if (listview1.checkeditems.indexof(item) >= 0) return true;
and
listviewitem item = new listviewitem(itemname); if (listview1.checkeditems.contains(item)) return true;
neither of worked. there way without looping through checkeditems , checking them 1 one?
you can benefit linq
purpose:
bool itemchecked = listview1.checkeditems.oftype<listviewitem>() .any(i => i.text == itemtext); //you can retrieve item itemtext using firstordefault() var checkeditem = listview1.checkeditems.oftype<listviewitem>() .firstordefault(i=>i.text == itemtext); if(checkeditem != null) { //do work...}
you can use containskey
determine if item (with name being itemname
) checked:
bool itemchecked = listview1.checkeditems.containskey(itemname);
Comments
Post a Comment