WPF ListView Selecting Multiple List View Items

前端 未结 5 2089
故里飘歌
故里飘歌 2021-02-07 12:21

I am figuring out a way to Select Multiple items in list view and deleting them on a certain action. What I can\'t figure out is, how should I have these multiple items selected

5条回答
  •  春和景丽
    2021-02-07 12:56

    You can do one of the following...

    ListView.SelectionMode = SelectionMode.Extended in code-behind or

    in XAML

    you also have 'multiple' selectionMode yet you could rather go for 'extended' which allows the user to select multiple items only using shift modifier.

    For deleting the items selected you could use the ListView.SelectedItems Propery as follows

    while( myListView.SelectedItems.Count > 0 )
    {
        myListView.Items.Remove(list.SelectedItems[0]);
    }
    

    [or you could use the SelectedIndices property]

    Hope this will avoid the issue you encountered :)

    Cheers!

提交回复
热议问题