by Viper
12. January 2009 08:17
Lot of time you want to display line number (row index) of rows in DataGrid in Row header of your grid very much like how each row in Microsoft Excel displays line number. One dirty solution is to add a new column in the grid at first position and then display its text as row number. There is more elegant solution available. You can actually set the Row.Header value to Row index in LoadingRow event of your grid.
protected GridRowLoading(object sender, DataGridRowEventArgs arg)
{
arg.Row.Header = arg.Row.GetIndex();
}
Make sure that you set HeaderVisibility property of your grid to "Row" or "All". By default row header is not visible.