ListView hide or collapse the selected group

How to hide or collapse a group in ListView?

I just add some elements

contactListView.Items.Add(new ISIMlistViewItem(contact));
if (contact.availability == 6)
    contactListView.Items[contact.identificator].Group = contactListView.Groups["offlineGroup"];
else
    contactListView.Items[contact.identificator].Group = contactListView.Groups["onlineGroup"];

And I want to hide sometimes offlineGroup.

if (hideOffline == true)
{
    // something like
    contactListView.Groups["offlineGroup"].Hide();
    // or
    contactListView.Groups["offlineGroup"].Visible = false;
}

But I do not know how I can do this. Can I just collapse it and not draw, or is there any way to hide it?

+5
source share
1 answer

It seems that the version of the .NET ListViewGroupclass does not provide a method Collapseor Expand.

Fortunately, the built-in control ListViewsupports it, and one guy provided an extension to enable U-turn and collapse .

Using your code, you can use the function to set the expand / collapse state with:

private void SetGroupCollapse(GroupState state)

, .

+4

All Articles