Grouping Display in C1TrueDBGrid

Presentation is one of the most important features when it comes to managing data in grids. When data are analysed and interpreted, the most challenging part of the job is done but it is far from being over. Just as important is to present and print the data in the right way because even the best interpretation will not achieve its goal if it is not presented in a clear, easy to understand and interesting way. Interactive data visualization goes a step further – moving beyond the display of static spreadsheets to drill down for more details, and interactively (and immediately) changing what data you see and how it is processed. ComponentOne TrueDBGrid takes into considerations all these needs and supports a GroupBy DataView which enables standard Microsoft Outlook-style grouping. Demo4

Grouping Records into Categories

The purpose of the GroupBy DataView is to allow users to dynamically configure a tree view type structure. When in Group mode, a "grouping area" is added to the top of the grid, providing an intuitive interface for specifying column groups. Basically, the grouping area is created when DataView is set to DataViewEnum.GroupBy. When AllowColMove is set to True, the grid will support the ability to move one or more columns into this area. Users can do this by selecting a single column and dragging its header into the grouping area. When a column is first added to the grouping area, nodes are added to the grid. Each node represents the unique value of the grouped column. Similarly when the last grouped column is removed from the area, the nodes are removed and the display will be similar to a normal grid.


c1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.GroupBy;  
c1TrueDBGrid1.AllowColMove = true;  

When the expand icon ("+") is clicked the grid expands and the next set of grouping column data appears. If there is another grouped column, then this column has an expand icon next to it also. With the addition of each grouped column, another level of sorted information gets added to the tree view. When the expand icon on the final column in the GroupedColumns collection is clicked the data in the remaining columns is displayed in the grid's Normal style.

Saving and Restoring the State of Grouped Rows

Once the user has expanded any row in the GroupedCollection, it is easy to save the "GroupedText" value of the expanded rows in an array list and restore them from the array list once required. This can be done even if the grid is not grouped anymore and there is any insertion or updation of the rows in the grid.


ArrayList ExpandedRows = new ArrayList();  
List GroupedColumn = new List();  
ArrayList NewRows = new ArrayList();  
string oldvalue = null;  
//Saving the Grouped Rows  
private void btn\_Save\_Click(object sender, EventArgs e)  
{  
ExpandedRows.Clear();  
GroupedColumn.Clear();  
SaveExpandedRows();  
for (int j = 0; j <= c1TrueDBGrid1.GroupedColumns.Count - 1; j++)  
{  
GroupedColumn.Add(c1TrueDBGrid1.GroupedColumns[j]);  
}  
}  
private void SaveExpandedRows()  
{  
this.ExpandedRows.Clear();  
Split v = c1TrueDBGrid1.Splits[0];  
if (c1TrueDBGrid1.DataView == DataViewEnum.GroupBy)  
{  
for (int i = 0; i <= v.Rows.Count - 1; i++)  
{  
if (v.Rows[i] is GroupRow && ((GroupRow)v.Rows[i]).RowType == RowTypeEnum.ExpandedGroupRow)  
{  
this.ExpandedRows.Add(((GroupRow)v.Rows[i]).GroupedText);  
}  
}  
}  
}  
//Restoring the Grouped Rows  
private void btn\_Restore\_Click(object sender, EventArgs e)  
{  
c1TrueDBGrid1.GroupedColumns.Clear();  
for (int m = 0; m <= GroupedColumn.Count - 1; m++)  
{  
c1TrueDBGrid1.GroupedColumns.Add(GroupedColumn[m]);  
}  
RestoreExpandedRows();  
}  
private void RestoreExpandedRows()  
{  
if (this.ExpandedRows.Count == 0)  
{  
return;  
}  
Split v = c1TrueDBGrid1.Splits[0];  
int lastRow = v.Rows.Count - 1;  
int row = 0;  
while (row <= lastRow)  
{  
if (v.Rows[row] is GroupRow)  
{  
GroupRow gr = (GroupRow)v.Rows[row];  
if (this.ExpandedRows.Contains(gr.GroupedText))  
{  
if (gr.RowType == RowTypeEnum.CollapsedGroupRow)  
{  
c1TrueDBGrid1.ExpandGroupRow(row);  
// After a row is expanded, number of visible rows in the grid is changed  
lastRow = v.Rows.Count - 1;  
}  
}  
else  
{  
if (gr.RowType == RowTypeEnum.ExpandedGroupRow)  
{  
c1TrueDBGrid1.CollapseGroupRow(row);  
// After a row is collapsed, number of visible rows in the grid is changed  
lastRow = v.Rows.Count - 1;  
}  
}  
}  
row = row + 1;  
}  
}  

Download Samples

CSharp
VB

GrapeCity

GrapeCity Developer Tools
comments powered by Disqus