Objectlistview how to change the text in the group header?
Asked Answered
T

1

7

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

Tashinatashkent answered 25/9, 2015 at 10:12 Comment(0)
J
8

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);
    }
};
Jubilant answered 25/9, 2015 at 11:5 Comment(2)
1. what is delegate and where should i write this code down? cuz I found the event "Abouttocreategroups" but it´s actually not working there 2. And what is MyRowObjectType? (which using should I use)?Tashinatashkent
AboutToCreateGroups is an ObjectListView event and is called before the groups are displayed. So you can actually make changes there to the groups that will directly reflect on the OLV. MyRowObjectType was just a placeholder for the underlying type of object that you use to populate the OLV. Access its Zeit property there add add them up.Jubilant

© 2022 - 2024 — McMap. All rights reserved.