|
1 | | -# How-to-display-the-RowIndex-in-RowHeaderCell-with-SfDatapager-in-WPF-DataGrid-SfDataGrid- |
2 | | -How to to display the RowIndex in GridRowHeaderCell when combined with SfDatapager in WPF DataGrid(SfDataGrid) |
| 1 | +# How to to display the RowIndex in GridRowHeaderCell when combined with SfDatapager in WPF DataGrid |
| 2 | + |
| 3 | +You can display the row index value in the RowHeaderCell by customizing its style with the binding of **RowIndex** to the **TextBlock**.**Text** property, as shown in the link below: |
| 4 | + |
| 5 | +[Display RowIndex at RowHeaderCell](https://support.syncfusion.com/kb/article/5182/how-to-display-rowindex-at-rowheadercell-in-sfdatagrid-in-wpf-) |
| 6 | + |
| 7 | +Currently, we do not have direct support to display the number of data in the GridRowHeaderCell when combined with SfDataPager. However, you can achieve this functionality by using a MultivalueConverter and handling the PageIndexChanged event in SfDataPager, as demonstrated below: |
| 8 | + |
| 9 | + ```C# |
| 10 | + |
| 11 | + private void SfDataPager_PageIndexChanged(object sender, PageIndexChangedEventArgs e) |
| 12 | + { |
| 13 | + for (int i = 1; i < dataGrid.RowGenerator.Items.Count; i++) |
| 14 | + { |
| 15 | + var rowHeaderCell = ((dataGrid.RowGenerator.Items[i] as DataRow).VisibleColumns[0] as DataColumn).ColumnElement; |
| 16 | + (rowHeaderCell as GridRowHeaderCell).RowIndex = -1; |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + ``` |
| 21 | + |
| 22 | + ```C# |
| 23 | + |
| 24 | + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) |
| 25 | + { |
| 26 | + var dataPager = values[2] as SfDataPager; |
| 27 | + |
| 28 | + if (dataPager.PageIndex == 0 || (int)values[0] == -1) |
| 29 | + { |
| 30 | + return values[0].ToString(); |
| 31 | + } |
| 32 | + |
| 33 | + values[0] = (int)values[0] + (((dataPager.PageIndex + 1) - 1) * dataPager.PageSize); |
| 34 | + return values[0].ToString(); |
| 35 | + |
| 36 | + } |
| 37 | + |
| 38 | + ``` |
| 39 | + |
| 40 | +The index is displayed in RowHeaderCell based on the above customized style like below, |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +Take a moment to peruse the [WPF DataGrid - Row Header](https://help.syncfusion.com/wpf/datagrid/rows#row-header) documentation, to learn more about Row Header code examples. |
0 commit comments