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

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -