简体   繁体   中英

How to clear all Groups And Items in Listview Control

如何在Listview控件中清除所有组和该组中的所有项目

Probably ListView.Clear() will work for you. And to clear groups in ListView call ListViewGroupCollection.Clear()

if you are filling your group items with datasource then you could try something like this..

How about

 DataSource = null;
 DataBind();

If you want to remove only the listViewItems which are grouped, you can do following:

        foreach (var group in listView.Groups)
        {
            var listViewItemsToDelete = listView.Items.Cast<ListViewItem>().Where(item => Equals(item.Group, group));
            foreach (var itemToRemove in listViewItemsToDelete)
            {
                listView.Items.Remove(itemToRemove);
            }
        }
        listView.Groups.Clear();

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