ListView hide or collapse selected group
Asked Answered
P

2

9

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?

Psychophysics answered 16/9, 2012 at 8:38 Comment(1)
typecastexception.com/post/2012/05/09/…Badillo
B
6

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.

Binghi answered 16/9, 2012 at 9:10 Comment(1)
I've the same idea. But I though that I can simply hide any group I want and also simply show it again. I don't like move items from one group to some temp place to hide group and then back to show group. I think that I'll use collapse extension.Psychophysics
C
0

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.

Cortes answered 21/4, 2023 at 20:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.