Blogs

Blogs

DevExpress XAF – Add a List View Group Footer

Scenario

DevExpress by default gives you the functionality within the Model to group list views together based on a selected field and show a count of records within the Group Header as seen in the screenshot below.

A user can then expand each group to see each individual record. To give the user a better understanding and overview of the records we wish to add a group footer to each group and display a total of the Time In Days spent against each group.

Solution

Within the Module.Win project create a new blank View Controller and customise the code below as required within it to get the results you require.

/// <summary>
/// Called when [view controls created].
/// </summary>
protected override void OnViewControlsCreated()
{         
    base.OnViewControlsCreated();
 
    if (View.Id == "MyListView")
    {
        GridControl grid = (GridControl)View.Control;
        GridView view = (GridView)grid.FocusedView;
        view.Columns.View.OptionsSelection.MultiSelect = true;
        view.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CellSelect;
        view.OptionsView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
 
        GridColumn timeValueColumn = view.Columns["TimeInDays"];
        GridGroupSummaryItem timeValueSummaryItem = new GridGroupSummaryItem();
        timeValueSummaryItem.FieldName = "TimeInDays";
        timeValueSummaryItem.SummaryType = SummaryItemType.Sum;
        timeValueSummaryItem.DisplayFormat = "Personnel Total (Days) = {0:n2}";
        timeValueSummaryItem.Tag = 1;
        timeValueSummaryItem.ShowInGroupColumnFooter = timeValueColumn;
        view.GroupSummary.Add(timeValueSummaryItem);
    }
}

Implementing the above code creates a group footer against each group and displays a count of the Time In Days of each record within the group.

This website uses cookies to provide the best possible experience. By continuing to use our website you are agreeing to our use of cookies.