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
Post a Comment