Search code examples
c#winformsobjectlistview

How to check all items when I click group title?


I use ObjectListView to list all items. And I don't know how to receive the click event when I click the title of Group cell, which is generated by the ObjectListView.

I want to implement the function which checks (or unchecks) all items in the clicked group.


Edit:

I overcomed by add one button to check/uncheck the selected items. The ObjectListView will select all items of the clicked group, so I invoke the check/uncheck behavior by a button.


Edit:

The GroupTaskClicked event doesn't work. The version of ObjectListView is v2.6.0 (2012/10/20), with visual studio 2010.

Well, the GroupStateChanged event will fire, but it fires more than one time. I will explain more on my answer.


Solution

  • The GroupStateChanged will fire. I listen the event by following method.

     private void olvList_GroupStateChanged(object sender, BrightIdeasSoftware.GroupStateChangedEventArgs e)
            {
                Trace.WriteLine("Name:" + e.Group.Header + "\r\nSelected:" + e.Group.Selected + "\r\nFocused:" + e.Focused + "\r\n");
    
            }
    

    When I click a group cell, named "MyClickGroup", it will fire 2 events.

    Name:MyClickGroup
    Selected:True
    Focused:False
    Name:MyClickGroup
    Selected:True
    Focused:True
    

    If I click a group cell named "MyNewGroup" while another cell named "MyClickGroup" was clicked first, it will fire 4 events.

    Name:MyClickGroup
    Selected:True
    Focused:False
    Name:MyClickGroup
    Selected:False
    Focused:False
    Name:MyNewGroup
    Selected:True
    Focused:False
    Name:MyNewGroup
    Selected:True
    Focused:True
    

    So, the GroupStateChanged event , whose Selected and Focused state are True, means the selected and focused group cell currently. It is what I want about the clicked event on the group cell.