Skip to content

DevExpress-Examples/winforms-grid-display-summary-calculated-over-detail-rows-in-master-row

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Winforms Data Grid - Calculate a summary against detail rows and display it in a master row cell

This example creates an unbound column in the master GridView and handles the CustomUnboundColumnData event to calculate the number of detail rows and display the number in the master row.

Winforms Data Grid - Calculate a summary against detail rows and display it in a master row cell

public Form1() {
    // ...
    gridControl1.ForceInitialize();
    GridColumn col = gridView1.Columns.AddField("Tasks");
    col.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
    col.Visible = true;
    gridView1.CustomUnboundColumnData+=new DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(gridView1_CustomUnboundColumnData);
}
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) {
    GridView view = sender as GridView;
    if (e.Column.FieldName != "Tasks") return;
    if (!e.IsGetData) return;
    DataRow row = ((view.DataSource as IList)[e.ListSourceRowIndex] as DataRowView).Row;
    e.Value = row.GetChildRows("Project_Tasks").Length;
}

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)