winforms - C# Check if data exists in List View Windows Form -
what want getting set of data group identifier, this:
123456 123456 456789 456789 456789 135790
to
name quantity 123456 2 456789 3 135790 1
what i've done far:
foreach(string name in itemlist) //itemlist = 123456,123456... mentioned above { var listitems= lvtest.items.cast<listviewitem>; bool exists = listitems.where(item => item.text == name).any(); // check if item name exists in list view if (!exists) { listviewitem lvitem = new listviewitem(new string[] { name, "1" }); lvtest.items.add(lvitem); } else { listviewitem lvitem = lvtest.items.cast<listviewitem>.where(item => item.text == name).firstordefault(); int count = (int)lvitem.subitems[1].text; count = count + 1; lvitem.subitems[1].text = count.tostring(); } }
but won't work due issue "cannot assign method group implicitly-typed local variable" in line of
var listitems= lvtest.items.cast<listviewitem>
please , in advance.
why don't use this,
list<string> lststring = new list<string> { "123456", "123456", "456789", "456789", "456789", "135790" }; var lstgrouplist = lststring .groupby(item => item, (key, group) => new { key, items = group.tolist()}).tolist();
Comments
Post a Comment