This is a migrated thread and some comments may be shown as answers.

how to add sequence number to gridview

2 Answers 482 Views
GridView
This is a migrated thread and some comments may be shown as answers.
phil huang
Top achievements
Rank 1
phil huang asked on 13 Dec 2012, 08:48 AM
Hi,I am using RadGridView to show some data,anyone has any idea about how  to add a column of sequence number like this:
#,col1,col2,col3
1,v1_1,v1_2,v1_3
2,v2_1,v2_2,v2_3
3,v3_1,v3_2,v3_3
...
the # column have no much meaning,just show the sequence number of current row in the grid..
and I want the # column fixed no matter which column is the sort column..
thx.

2 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 18 Dec 2012, 06:24 AM
Hello Phil,

Thank you for writing.

You can achieve this using the rows header columns and the ViewCellFormatting of RadGridView. You should make sure the rows header columns is visible. By default this column is visible, so if you have not explicitly set the ShowRowHeaderColumn property of RadGridView to false there are no actions required. In the ViewCellFormatting event you can set the number for the given cell. You might also like to remove the image in the cell which will overlap with the numbers. Here is the code:
private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
  if (e.CellElement is GridRowHeaderCellElement && e.RowIndex >= 0)
  {
    e.CellElement.Text = (e.CellElement.RowIndex + 1).ToString();
    e.CellElement.Image = null;
  }
}

I hope this will be useful. Should you have further questions, I would be glad to help.
 
All the best,
Ivan Petrov
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
phil huang
Top achievements
Rank 1
answered on 28 Dec 2012, 09:04 AM
Hi,Ivan
that works..thx for your reply...
Telerik rocks! lol.
Tags
GridView
Asked by
phil huang
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
phil huang
Top achievements
Rank 1
Share this question
or