简体   繁体   中英

how to remove all uncheck items from listview c#

i need to remove all unchecked item from listview winforms c# in textchange event

for eg i need to do like below

private void textBox_supplierName_TextChanged(object sender, EventArgs e)
{

  if (listView_supplierNames.CheckedItems==CheckState.Unchecked)
  {
        // remove item    
  }
}

how to do it ...thanks

Use ListViewItem.Remove method to remove item from its associated ListView control:

foreach (ListViewItem item in listView_supplierNames.Items)
    if (!item.Checked)
        item.Remove();

Loop through the ListView Items and Use ListViewItem.Remove to Remove Items

foreach (ListViewItem item in listView_supplierNames.Items)
            {
                if (item.Checked)
                {

                }
                else
                {
                    //Remove unchecked Items
                     listView1.Items.Remove(item);
                }
            }

Get all the unchecked items and use Remove - example-

foreach(var item in listView.SelectedItems)
{
   listView.Items.Remove(item)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM