DataGrid for WPF and Silverlight Overview > DataGrid Features > Freezing > Freezing Grid Rows |
You may want to freeze the top or bottom rows in the grid at so that they are always visible even when the grid is scrolled vertically at run time. This feature is not enabled by default, but if you choose you can enable the row freezing feature by setting the FrozenTopRowsCount and FrozenBottomRowsCount properties.
At Design Time
To freeze the top and bottom two rows, complete the following steps:
In XAML
For example to freeze the top and bottom two rows, add FrozenTopRowsCount="2" FrozenBottomRowsCount="2" to the <c1:C1DataGrid> tag so that it appears similar to the following:
<c1:C1DataGrid Name="c1datagrid1" Height="180" Width="250" FrozenTopRowsCount="2" FrozenBottomRowsCount="2" />
In Code
For example, to freeze the top and bottom two rows, add the following code to your project:
Visual Basic |
Copy Code
|
---|---|
Me.C1DataGrid1.FrozenTopRowsCount = True Me.C1DataGrid1.FrozenBottomRowsCount = True |
C# |
Copy Code
|
---|---|
this.c1DataGrid1.FrozenTopRowsCount = true; this.c1DataGrid1.FrozenBottomRowsCount = true; |
What You've Accomplished
Run the application and observe that the two top and bottom rows are frozen. Scroll the grid vertically and notice that the top two an bottom two rows do not scroll and are locked in place. By default the Add New row appears as the last row in the grid and so will be one of the frozen rows.