Reputation: 857
How to add a column in wpf datagrid that shows a numeric list for each row like in excel?
Upvotes: 0
Views: 66
Reputation: 39956
Add LoadingRow
event to your DataGrid
:
<DataGrid LoadingRow="grd_OnLoadingRow" Name="grd" ... >
Then:
private void grd_OnLoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = (e.Row.GetIndex()).ToString();
}
But it start counting from 0
if you want to start from 1
you can try this:
e.Row.Header = (e.Row.GetIndex() + 1).ToString();
Upvotes: 3