I just want to add a index column in wpf toolkit DataGrid
to show row index of each data in the DataGrid
. How?
<dg:DataGrid ItemsSource="{Binding List}"
SelectionMode="Extended"
IsReadOnly="True"
AutoGenerateColumns="False"
HorizontalAlignment="Left">
<dg:DataGrid.Columns>
**<dg:DataGridTextColumn Header="Row Index"></dg:DataGridTextColumn>**
<dg:DataGridTextColumn Header="Branch"
Binding="{Binding Branch.Id}"></dg:DataGridTextColumn>
<dg:DataGridTextColumn Header="Count"
Binding="{Binding RequestCount}"></dg:DataGridTextColumn>
</dg:DataGrid.Columns>
</dg:DataGrid>
you can use a multibinding and a converter to bind to the item in the row and the parent datagrid. then in the converter you look up the position of the row in the datagrids items.
On this page download the sample WPFDatagridWithRowNumbers.zip
Enjoy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With