Assembly: Dapfor.Wpf (in Dapfor.Wpf.dll) Version: 4.1.0.26317 (4.1.0.26317)
Syntax
C# |
---|
public class Column : INotifyPropertyChanged |
Visual Basic |
---|
Public Class Column Implements INotifyPropertyChanged |
Visual C++ |
---|
public ref class Column : INotifyPropertyChanged |
F# |
---|
type Column = class interface INotifyPropertyChanged end |
Remarks
In GridControl headers are used for storing columns that can be used to manage content display and grouping and to display content with different presentations on different hierarchy levels. Header columns are added both in XAML and in C# or VB code:
Copy | |
---|---|
<!-- XAML code --> <df:Header> <df:Header.Columns> <df:Column Id="Id0" Title="Column 0"/> <df:Column Id="Id1" Title="Column 1"/> <df:Column Id="Id2" Title="Column 2"/> </df:Header.Columns> </df:Header> |
Copy | |
---|---|
// C# code Header header = new Header(); header.Add(new Column("Id0", "Column 0")); header.Add(new Column("Id1", "Column 1")); header.Add(new Column("Id2", "Column 2")); |
The Header provides several convenient accessories to control and manage sequence, column visibility and data grouping. The following code demonstrates a way of receiving all header columns (both visible and invisible).
Copy | |
---|---|
//Some code here... Header header = ...; //Enumerate all columns in header foreach (Column column in header.Columns) { //Some code here... } //Enumerate all grouped columns foreach (Column column in header.GroupedColumns) { //Some code here... } //Enumerate all sorted columns foreach (Column column in header.SortedColumns) { //Some code here... } //Find a column by its identifier or position: Column column1 = header["MyColumn"]; Column column2 = header[5]; |
The column provides the following properties to establish column position in the header: Column.Index, Column.VisibleIndex. The column may also be moved to any position in header using programming means:
Copy | |
---|---|
Column column = header["MyColumn"]; column.VisibleIndex = 5; |
A Header is responsible for column sorting. Column sorting is set with Column.SortDirection property. Sorting direction is defined by SortDirection. Sequence of multiple sorting depends on sorting level. To understand sorting level of a column, one should just call a Column.SortLevel property. A list of all sorted columns can be obtained with Header.SortedColumns. An example of most frequent usage of sorting in a grid is shown below.
Copy | |
---|---|
Header header = ...; Column column1 = header["Column1"]; Column column2 = header["Column2"]; //Sort by the first column column1.SortDirection = SortDirection.Ascending; //Turn on the multiple sort by the second column column2.SortDirection = SortDirection.Descending; Debug.Assert(header.SortedColumns[0].Id == "Column1"); Debug.Assert(header.SortedColumns[1].Id == "Column2"); Debug.Assert(column1.SortLevel == 0); Debug.Assert(column2.SortLevel == 1); Debug.Assert(header.SortedColumns.Count == 2); //Enumerate all sorted columns foreach (Column column in header.SortedColumns) { //Some code here... } //Clear sort header.SortedColumns.Clear(); |
The Header class can be used to group content by one or multiple columns. Since a grid may have multiple headers, grouping can be done on multiple hierarchy levels simultaneously.
To group data by one column, one has to set Column.Grouped property to true. Multiple grouping of data by various columns can be implemented by sequential setting of this property for such columns. Grouping is visually represented on the group panel, where columns can be dragged by user from the column panel. Height of this panel can be adjusted with Header.GroupPanelHeight property.
Copy | |
---|---|
Header header = ...; Column column1 = header["Column1"]; Column column2 = header["Column2"]; column1.Grouped = true; //Group the content by the first column column1.Grouped = true; //Turn on multiple grouping column2.Grouped = true; Debug.Assert(header.GroupedColumns[0].Id == "Column1"); Debug.Assert(header.GroupedColumns[1].Id == "Column2"); Debug.Assert(column1.GroupIndex == 0); Debug.Assert(column2.GroupIndex == 1); Debug.Assert(header.GroupedColumns.Count == 2); //Enumerate all grouped columns foreach (Column column in header.GroupedColumns) { //Some code here... } //Ungroup the content header.GroupedColumns.Clear(); |
A programmer may also set column visibility and position. To define a manage visibility columns have Column.Visible property. Column visibility covers only the column panel. It is also possible to group data by hidden columns. Moreover, columns that are used for grouping are usually not displayed. An example of managing column visibility via API is shown below:
Copy | |
---|---|
Header header = new Header(); header.Columns.Add(new Column("Column1")); header.Columns.Add(new Column("Column2")); Debug.Assert(header[0].Id == "Column1"); Debug.Assert(header[1].Id == "Column2"); Debug.Assert(header.VisibleColumns[0].Id == "Column1"); Debug.Assert(header.VisibleColumns[1].Id == "Column2"); Debug.Assert(header["Column1"].VisibleIndex == 0); Debug.Assert(header["Column2"].VisibleIndex == 1); //Hide the first column header["Column1"].Visible = false; //The header has the single visible column Debug.Assert(header.VisibleColumns.Count == 1); Debug.Assert(header.VisibleColumns[0].Id == "Column2"); Debug.Assert(header["Column2"].VisibleIndex == 0); //Enumerate all visible columns foreach (Column column in header.VisibleColumns) { //Some code here... } //Hide all columns header.VisibleColumns.Clear(); |
Moving columns (i.e. changing positions of visible columns) is also a trivial task. An example of moving a visible column to header beginning or end is shown below:
Copy | |
---|---|
Header header = ...; Column column = header["Column1"]; //Move the column to the beginning column.VisibleIndex = 0; //Move the column to the end column.VisibleIndex = header.VisibleColumns.Count - 1; |