How to display row number in Row header of DataGrid

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.

Views: 2817

Tags:

ASP.Net | Silverlight | DataGrid

Comments

12/20/2008 10:34:26 AM #

viper

There is a typo in the post. HeaderVisibility should be set to "Row" if you want to display row headers only, set it to "Column" if you want column headers only. Or set it to "All" if you want both headers displayed.

viper United States

5/6/2009 6:19:36 AM #

Single Latin Women

Thanks for the info.Very practical posts.Keep it up!

Single Latin Women United States

10/8/2009 4:24:27 AM #

Babying the Baby from Eczema

A very little thing yet so helpful in many ways. thanks for the info!

Babying the Baby from Eczema United States

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli