c# - delete same value listbox and arraylist -


foreach (student student in liststu) {     listbox1.items.add(student.tostring()); } foreach (staff staff in liststa) {     listbox1.items.add(staff.tostring()); } 

i have 2 arraylist liststa liststu used fill listbox. i'm trying delete listbox , arrylist @ same time , i'm trying remove() don't know how correct value listbox delete in arraylist.

for (int = listbox1.selectedindices.count - 1; >= 0; i--) {     listbox1.items.removeat(listbox1.selectedindices[i]);     liststa.remove(listbox1.selectedindex.tostring());  } 

how correct value listbox use arraylist's remove()

the issue here .remove trying find specific string value, not index.

for example, you're trying remove string "2" arraylist of objects, not index 2

it sounds wish remove index, use .removeat on arraylist well

listbox1.items.removeat(listbox1.selectedindices[i]); liststa.removeat(listbox1.selectedindices[i]); 

this requires listtsa , listbox1 kept in sync


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -