While searching I found that, row number can be set to RowHeader easily:
void datagrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = e.Row.GetIndex();
}
It sets row number in RowHeader. But I want to show Row number to first column
Can any one help me how can I achieve this? Thanks
There might be an easier way to do this but I got it to work by using the GetIndex() method on the DataGridRow class. This returns the index in to the data source so might not be exactly what you're after.
the xaml
and the converter.
I used Andys example, but I needed to use it from the code behind, so he is my code just in case anyone is looking to do the same as googling was a bit barren.
The C#
Andy's Converter, just added
return row.GetIndex() - 1;
to start the count at 1, rather than 0.Also don't forget the using's