You can replace rows the data grid uses to show the data of each data item or group with custom rows, or you can add custom rows on top or bottom of data item rows.
Replacing Data Item Row
In order to replace the rows generated by the data grid you must add a handler to the CreatingRow event.
The following code replaces the default row with a template row:
Visual Basic |
Copy Code
|
---|---|
Private Sub C1DataGrid_CreatingRow(sender As Object, e As DataGridCreatingRowEventArgs) 'Check if it's an item row (it could be a group row too). If e.Type = DataGridRowType.Item Then e.Row = New DataGridTemplateRow() With { _ .RowTemplate = DirectCast(Resources("TemplateRow"), DataTemplate) _ } End If End Sub |
C# |
Copy Code
|
---|---|
private void C1DataGrid_CreatingRow(object sender, DataGridCreatingRowEventArgs e) { //Check if it's an item row (it could be a group row too). if (e.Type == DataGridRowType.Item) { e.Row = new DataGridTemplateRow() { RowTemplate = (DataTemplate)Resources["TemplateRow"] }; } } |
Adding an Extra Row
DataGrid for WPF allows adding one or more rows on top or bottom of data. This functionality is used in the new row, total row, summary row, and filter row scenarios.
For example, in XAML or code:
XAML |
Copy Code
|
---|---|
<c1:C1DataGrid> <c1:C1DataGrid.TopRows> < local:DataGridFilterRow /> </c1:C1DataGrid.TopRows> <c1:C1DataGrid.BottomRows> < local:DataGridFilterRow/> </c1:C1DataGrid.BottomRows> </c1:C1DataGrid> |
Visual Basic |
Copy Code
|
---|---|
grid.Rows.TopRows.Add(New DataGridFilterRow()) |
C# |
Copy Code
|
---|---|
grid.Rows.TopRows.Add(new DataGridFilterRow());
|