Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show row index for wpf toolkit datagrid?

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>
like image 428
NetSide Avatar asked Dec 22 '22 06:12

NetSide


1 Answers

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!

like image 200
Aran Mulholland Avatar answered Dec 28 '22 08:12

Aran Mulholland