Tinaira
Tinaira

Reputation: 857

Add Numeric list column for each row like in excel

enter image description here

How to add a column in wpf datagrid that shows a numeric list for each row like in excel?

enter image description here

Upvotes: 0

Views: 66

Answers (1)

Salah Akbari
Salah Akbari

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

Related Questions