문제

please help me how can remove more than 1 item in a listbox.I know the code for removing 1 item: listbox.Items.RemoveAt(i) but for more than 1 item selected in a listbox,what is the code? write the code for example in button-click event.I have only a button and a listbox in my winform.(write codes in C#)

도움이 되었습니까?

해결책

while(listbox.SelectedItems.Count > 0)
 {
    listbox.Items.Remove(listbox.SelectedItem);
 }

다른 팁

ListBox1.ClearSelection();

    //or

    foreach (ListItem listItem in ListBox1.Items)
    {
        listItem.Selected = false;
    }


     List<ListItem> itemsToRemove = new List<ListItem>();
    foreach (ListItem listItem in ListBox1.Items)
    {
        if (listItem.Selected)
            itemsToRemove.Add(listItem);
    }

    foreach (ListItem listItem in itemsToRemove)
    {
        ListBox1.Items.Remove(listItem);
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top