hi friends......
I need to print the row number in the row header of datagrid.what is the code for that?
plz help me......
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
William ClardyPosted Oct 8, 2009, 6:15 PM
int hpadding = 40;
Graphics graphic = gridview.CreateGraphics();
gridview.RowHeadersWidth = (int)graphic.MeasureString(gridview.RowCount.ToString("N0"), gridview.Font).Width + hpadding ;
graphic.Dispose();
gridview.RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight ;
foreach (DataGridViewRow dr in gridview.Rows)
{
dr.HeaderCell.ValueType = System.Type.GetType("System.String");
dr.HeaderCell.Value = (dr.Index + 1).ToString("N0");
}
I hope it helps.
(warning: I'm really a VB.Net kind of guy, so this may not be an optimal solution)
Soumya SurendranPosted Oct 1, 2009, 7:11 AM
private void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
{
DataGridView Gview = sender as DataGridView;
if (null != Gview)
{
Gview.Rows[e.RowIndex].HeaderCell.Value = Convert.ToString(dataGridView1.CurrentRow.Index+1);
}
}
Resmy RaviPosted Oct 1, 2009, 3:28 AM
can you please give me the code?
Nir BarPosted Sep 30, 2009, 7:47 AM
You can inherit DataGridViewRowHeaderCell and override it's Value member to be equal RowIndex + 1
You will need to set HeaderCell of every row to your custom type. You can do that in RowsAdded event of the DataGridView
Please mark this post as an answer if it helps you
Nir
Resmy RaviPosted Sep 30, 2009, 7:27 AM
I need to print in the row header itself...
is there any alternate solution for that?
naura paxPosted Sep 30, 2009, 7:02 AM
one possible way is to add a column at position 0 of datagrid and
setting its value to rowindex+1 at RowAdded event.
Please mark as answered if helpful.