Reputation: 2063
How can I hide or collapse some group in ListView
?
I just add some items
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 sometimes hide the offlineGroup
.
if (hideOffline == true)
{
// something like
contactListView.Groups["offlineGroup"].Hide();
// or
contactListView.Groups["offlineGroup"].Visible = false;
}
But I don't know how can I do that. Can I just collapse it and don't draw it or is there any possibility to hide it?
Upvotes: 9
Views: 27362
Reputation: 734
Here is the source code of control derived from ListView which has Collapsable logic properly implemented:
https://www.codeproject.com/Articles/36775/Collapsible-ListViewGroup
Using this control, and after creating the items and groups I had to call:
lvIssues.SetGroupState(ListViewGroupState.Collapsible);
And my groups turned nicely into collapsable.
Upvotes: 0
Reputation: 40736
It seems that the .NET version of the ListViewGroup
class does not provide a Collapse
or Expand
method.
Luckily, the native ListView
control does support it and one guy provided an extension to enable expand and collapse.
Using his code you can then have a function to set the expand/collapse state with:
private void SetGroupCollapse(GroupState state)
For hiding a complete group I would simply remove all the items in this group.
Upvotes: 6