Gets a collection of grouped Columns.

Namespace: Dapfor.Net.Ui
Assembly: Dapfor.Net (in Dapfor.Net.dll) Version: (


public Header..::..GroupedColumnCollection GroupedColumns { get; }
Visual Basic
Public ReadOnly Property GroupedColumns As Header..::..GroupedColumnCollection
Visual C++
property Header..::..GroupedColumnCollection^ GroupedColumns {
	Header..::..GroupedColumnCollection^ get ();
member GroupedColumns : Header..::..GroupedColumnCollection with get

Property Value

Type: Header..::..GroupedColumnCollection
The grouped Columns.


.Net Grid enables multiple data grouping in headers of the .Net Grid by any columns at any hierarchical level. When data is grouped by a specific column, .Net Grid searches all rows within a group that has similar values. When a group is organized, a row that doesn't contain a data object is added to the data grid. The Row.IsGroup property of such row will always return true, and Row["column id"].Value will return a value by which data is grouped. All rows with values that meet grouping conditions are attached to the newly created group. Before a new data object is added, .Net Grid verifies whether there is any group with the required value on the current hierarchical level. If there is no such group, a new group is created. When the Row.Update() method is invoked, the grid checks whether a row conforms to group value. If there are no more rows in the group, the group is removed from the grid.

In programming the grouping feature can be enabled via the Column.Grouped property. Sequential invocation of this property for several columns results in data grouping of these columns. The column with grouping remains visible unless Column.Visible property is set to false. Sorting (and multiple sorting) can be enabled or disabled for grouped columns because sorting and grouping are completely independent processes. The list of grouped columns can be viewed with Header.GroupedColumns collection property. A user can also group columns in the data grid. To use this ability the user just needs to drag a column to a special panel on the grid's header. However, this is not possible if height of this panel is set to 0.

Grouping and data filtering
When grouping and filtering are enabled simultaneously, the .Net Grid checks every group for visible rows. If there are no visible rows, the group is filtered. If a single unfiltered row appears, the row of the group also becomes visible.

 Copy imageCopy
public void GroupedColumnsExample(Grid grid)
    //Add a new header on the top hierarchical level (level 0)
    Header header = new Header();
    header.Add(new Column("Column1"));
    header.Add(new Column("Column2"));
    header.Add(new Column("Column3"));

    Console.WriteLine("Grouped columns count: {0}", header.GroupedColumns.Count);

    header["Column1"].Grouped = true;
    header["Column3"].Grouped = true;
    Console.WriteLine("Columns count: {0}", header.Count);
    Console.WriteLine("Grouped columns count: {0}", header.GroupedColumns.Count);

    //Move the last grouped column to the upper level
    header.GroupedColumns[1].GroupIndex = 0;

    //Iterate all grouped columns
    foreach (Column column in header.GroupedColumns)
        Console.WriteLine("Grouped column: id = '{0}', index = {1}, group index = {2}, visible index = {3}", column.Id, column.Index, column.GroupIndex, column.VisibleIndex);

    //Ungroup all columns
    Console.WriteLine("Columns count: {0}", header.Count);
    Console.WriteLine("Grouped columns count: {0}", header.GroupedColumns.Count);

//Console output:
Grouped columns count: 0
Columns count: 3
Grouped columns count: 2
Grouped column: id = 'Column3', index = 2, group index = 0, visible index = 2
Grouped column: id = 'Column1', index = 0, group index = 1, visible index = 0
Columns count: 3
Grouped columns count: 0

Non-event model
Real-time grouping in non event-driven model is done with Row.Update method.

 Copy imageCopy
public void NonEventModelGrouping(Grid grid)
    //Initialize the grid
    grid.Headers.Add(new Header());
    grid.Headers[0].Add(new Column("Name"));
    grid.Headers[0].Add(new Column("Color"));
    grid.Headers[0].Add(new Column("Price"));

    //Group data by color
    grid.Headers[0]["Color"].Grouped = true;

    //Populate the grid
    Row blackMercedes = grid.Rows.Add(new object[] { "Mercedes", Color.Black, 25000d });
    Row whiteMercedes = grid.Rows.Add(new object[] { "Mercedes", Color.White, 23000d });
    Row whiteBMW = grid.Rows.Add(new object[] { "BMW", Color.White, 35000d });

    //The grid has two groups - 1=> black mercedes 2=> white mercedes and bmw

    //The first group has only the black mercedes
    Assert.AreEqual(1, grid.Nodes[0].Children.Count);
    Assert.AreEqual("Mercedes", grid.Nodes[0].Children[0]["Name"].Value);

    //The second group has two cars: white mercedes and white bmw
    Assert.AreEqual(2, grid.Nodes[1].Children.Count);
    Assert.AreEqual("Mercedes", grid.Nodes[1].Children[0]["Name"].Value);
    Assert.AreEqual("BMW", grid.Nodes[1].Children[1]["Name"].Value);

    //Change color of the white mercedes
    whiteMercedes["Color"].Value = Color.Green;

    //Now we have 3 groups. The last contains only the green mercedes
    Assert.AreEqual(1, grid.Nodes[2].Children.Count);
    Assert.AreEqual("Mercedes", grid.Nodes[2].Children[0]["Name"].Value);
    Assert.AreEqual(Color.Green, grid.Nodes[2].Children[0]["Color"].Value);

Event-driven model
In the event-driven model Row.Update method is called every time when a data object sends a notification. Once again we'd like to emphasize the importance of such model as it removes dependency of the business layer on System.Windows.Forms controls and on Dapfor assemblies as well.

See Also