FlexGrid for WinForms
集計
選択範囲 > 集計

FlexGrid provides selection statistics, which can be used to display Excel-style data summaries in the footer. It allows you to display the statistics of the basic functions and operations performed on the selected cell range. These functions or operations include aggregate operations such as sum, average, count, maximum number, minimum number, and count distinct which can be applied to the selected cells from the context menu. You can use the Aggregate property of the AggregateDefinition class to provide data summary for the selected cell range.

The Aggregate property uses AggregateEnum enumeration to set the aggregate function to be applied on the cells by setting one of the following values:

To show the selection statistics at the footer of the grid, we have added a ToolStripLabel named 'tslSelectionStatistics' docked at the bottom of the grid. Then, add the below code to the SelChange event of the C1FlexGridBase class. This event fires when the user extends the selection with the mouse in the grid.

C#
コードのコピー
private void c1FlexGrid1_SelChange(object sender, EventArgs e)
{
    var text = string.Empty;
    if (!flexGrid1.Selection.IsSingleCell)
    {
        text = $"Average: {flexGrid1.Aggregate(AggregateEnum.Average):F2}  " +
       $"Count: {flexGrid1.Aggregate(AggregateEnum.Count)}  " +
       $"Summary: {flexGrid1.Aggregate(AggregateEnum.Sum):F2}";
    }
    //Gets the text to be displayed on the toolstrip label
    tslSelectionStatistics.Text = text;
}