ListBox Item Removal

后端 未结 5 1430
长发绾君心
长发绾君心 2021-01-14 19:15

I have a WPF window that manages sets of configurations and it allows users to edit a configuration set (edit button) and to remove a configuration set (remove button). The

5条回答
  •  醉梦人生
    2021-01-14 20:16

    for (int i = lstAttachments.SelectedItems.Count - 1; i >= 0; i--)
    {
       lstAttachments.Items.Remove(lstAttachments.SelectedItems[i]);
    }
    

    Simplest way to remove items from a list you iterate through is going backwards because it does not affect the index of items you are moving next to.

提交回复
热议问题