none
Is it Possible to Delete Multiple Selected items in 2 ListView ??. RRS feed

Answers

  •  

    Where I have to add another ListView Name ??

    I have 2 ListView, 1) ListView_PhoneNumber 2) ListView_UserPass

    Like this, one ListView at a time

    private void RemoveSelectedButton_Click(object sender, EventArgs e)
    {
        ListView_PhoneNumber.Items.Cast<ListViewItem>()
            .Where(listViewItem => listViewItem.Selected)
            .Select(listViewItem => listViewItem)
            .ToList()
            .ForEach(listViewItem => ListView_PhoneNumber.Items.Remove(listViewItem));
    }

    Do the same for the other ListView. Does this make it clear for you?

    ListView_PhoneNumber.Items.Cast<ListViewItem>()
    .Where(listViewItem => listViewItem.Selected)
    .Select(listViewItem => listViewItem)
    .ToList()
    .ForEach(listViewItem => ListView_PhoneNumber.Items.Remove(listViewItem));

    ListView_UserPass.Items.Cast<ListViewItem>()
    .Where(listViewItem => listViewItem.Selected)
    .Select(listViewItem => listViewItem)
    .ToList()
    .ForEach(listViewItem => ListView_UserPass.Items.Remove(listViewItem));




    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Sahana M Friday, November 29, 2019 12:37 PM
    Friday, November 29, 2019 11:22 AM
    Moderator

All replies

  • Hello,

    In the following example change ownerContactListView to the name of your ListView.

    private void RemoveSelectedButton_Click(object sender, EventArgs e)
    {
        ownerContactListView.Items.Cast<ListViewItem>()
            .Where(listViewItem => listViewItem.Selected)
            .Select(listViewItem => listViewItem)
            .ToList()
            .ForEach(listViewItem => ownerContactListView.Items.Remove(listViewItem));
    }


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, November 29, 2019 10:48 AM
    Moderator
  •  

    Where I have to add another ListView Name ??

    I have 2 ListView, 1) ListView_PhoneNumber 2) ListView_UserPass

    Friday, November 29, 2019 11:01 AM
  •  

    Where I have to add another ListView Name ??

    I have 2 ListView, 1) ListView_PhoneNumber 2) ListView_UserPass

    Like this, one ListView at a time

    private void RemoveSelectedButton_Click(object sender, EventArgs e)
    {
        ListView_PhoneNumber.Items.Cast<ListViewItem>()
            .Where(listViewItem => listViewItem.Selected)
            .Select(listViewItem => listViewItem)
            .ToList()
            .ForEach(listViewItem => ListView_PhoneNumber.Items.Remove(listViewItem));
    }

    Do the same for the other ListView. Does this make it clear for you?

    ListView_PhoneNumber.Items.Cast<ListViewItem>()
    .Where(listViewItem => listViewItem.Selected)
    .Select(listViewItem => listViewItem)
    .ToList()
    .ForEach(listViewItem => ListView_PhoneNumber.Items.Remove(listViewItem));

    ListView_UserPass.Items.Cast<ListViewItem>()
    .Where(listViewItem => listViewItem.Selected)
    .Select(listViewItem => listViewItem)
    .ToList()
    .ForEach(listViewItem => ListView_UserPass.Items.Remove(listViewItem));




    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Sahana M Friday, November 29, 2019 12:37 PM
    Friday, November 29, 2019 11:22 AM
    Moderator