Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
710
Removing selected items
posted

This must be very simple, but I do not manage to remove the selected items from the listview.

 I am using:

ultraListView1.SelectedItems.Clear();

 

My listview is in detailed mode with 3columns.

 

Thanks for your help.

Parents
No Data
Reply
  • 69832
    Offline posted

    It seems as if you are expecting the line of code you posted to remove the selected items from the control's Items collection; it doesn't, it deselects them, i.e., removes them from the SelectedItems collection. You can use the UltraListView.Items.Remove method on each member of the SelectedItems collection to remove all selected items, as demonstrated by the following code sample:

    this.listView.KeyDown += new KeyEventHandler(listView_KeyDown);

    private void listView_KeyDown(object sender, KeyEventArgs e)
    {
        UltraListView listView = sender as UltraListView;

        if ( e.KeyData == Keys.Delete )
        {
            object[ selectedItems = listView.SelectedItems.All;
           
            listView.BeginUpdate();

            for ( int i = 0; i < selectedItems.Length; i ++ )
            {
                UltraListViewItem item = selectedItemsIdea as UltraListViewItem;
                listView.Items.Remove( item );
            }

            listView.EndUpdate();
        }
    }

     

Children
No Data