开发者

How to Remove Selected Items from Multiple List Boxes

开发者 https://www.devze.com 2023-03-28 15:16 出处:网络
I have two listboxes and listbox1 selected index changed Event has the code : listBox2.SelectedIndex = listBox1.SelectedIndex

I have two listboxes and listbox1 selected index changed Event has the code :

      listBox2.SelectedIndex = listBox1.SelectedIndex

so when i click the item in one listbox , the Item with the same Index is selected automatically in another listbox, now i wanna remove these two items with a button . when i write the following code :

      listBox1.Items.Remove(listBox1.SelectedItem);
      listBox2.Items.Re开发者_运维问答move(listBox2.SelectedItem);

It Deletes only the Listbox1 SelectedItem , why not it is Deleting ListBox 2 selectedItem ?? I need Urgent Help / Response .I Would be very Greatful/ThankFul to all of YOU. THANKS IN ADVANCE ,


try to delete them in another order:

  listBox2.Items.Remove(listBox2.SelectedItem);
  listBox1.Items.Remove(listBox1.SelectedItem);

When you deleted the selecteditem at the first ListBox, SelectionChanged is firing and set SelectedItem of listbox2 into null.


Another solution is to keep the selected index of each listbox in two separate variables and then delete each item by the index stored beforehand.

0

精彩评论

暂无评论...
验证码 换一张
取 消