Search code examples
c#listviewsumobjectlistview

Objectlistview how to change the text in the group header?


I want to change the name of the group header but i cant find any solutions in the documentation or on google.

the text in the header should be a time which is summed up in the group.

this is how it should look like:

enter image description here


Solution

  • the text in the header should be a time which is summed up in the group.

    No problem :)

    olv.AboutToCreateGroups += delegate(object sender, CreateGroupsEventArgs args) {
        foreach (OLVGroup olvGroup in args.Groups) {
            int totalTime = 0;
    
            foreach (OLVListItem item in olvGroup.Items) {
                // change this block accordingly
                 MyRowObjectType rowObject = item.RowObject as MyRowObjectType;
                 totalTime += rowObject.MyNumericProperty;
                // change this block accordingly
            }
    
            olvGroup.Header += String.Format(" (Total time = {0})", totalTime);
        }
    };