c# - how can I check if listview1 item in not present anymore in listview2 and fire an event? -
i dont think saw this, searched through net find using foreach loop.
what wanted if listview1 dont have items named "joshua", change listview2's "joshua" "incomplete" "complete".
listview1 can have 2 or more "joshua", until "joshua" gone listview2 must stay "incomplete". when "joshua" gone in listview1, thats when listview2's "joshua" "complete".
i used loop, doesnt change incomplete complete. think might wrong @ looping itself.
i had put in timer1_tick since listview1 items can removed when time expires.
here code:
for (int lst = 0; lst < listview2.items.count; lst++) { (int dgv = 0; dgv < datagridview1.rows.count; dgv++) { if (listview2.items[lst].subitems[0].text == listview1.items[dgv].subitems[0].text ) { continue; } else if (listview2.items[lst].subitems[0].text != listview1.items[dgv].subitems[0].text ) { listview2.items[lst].subitems[1].text = "complete"; } } }
you don't need loop through list view items. requirement continually check if listview1 has particular item (joshua in case.), , if doesn't have that, change status in listview2.
what create method , pass list of strings it. list of strings list items want search such joshua.
then, each item in list, if listview1 contains it, change status of said item in listview2. elsewhere, you'd update list of strings items want check for.
private void timertick(object sender, eventargs e) { // items list of string contains strings search for, such "joshua" changestatus(items); } private void changestatus(list<string> items) { foreach(string in items) { if(!lv1.items.contains(it)) { // change status of 'it' in listview2 incomplete complete // change if status 'incomplete'. no point in changing if it's 'complete'. } } } you didn't specify if wpf or winforms. if it's former, best way go have 2 observablecollection collections items representing each list view. , data bind 2 collections list views, , manipulate observablecollections see if items exists etc, , wpf automatically take care of listview representation of data.
Comments
Post a Comment