Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have windows form in c# on the form i have a datagridview that populate data from an oracle table ... i want to make the first index of the datagridview a series of number for example for first row 1 and for second row 2 ...., and the displayed data Begin from the second index
Posted
Updated 5-Apr-23 1:00am
v2

 
Share this answer
 
private void metroGrid1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
    {
        using (SolidBrush b = new SolidBrush(((DataGridView)sender).RowHeadersDefaultCellStyle.ForeColor))
        {
            e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4);
        }
    }
 
Share this answer
 
Comments
CHill60 3-May-18 4:51am    
How does this answer this 4 year old question?
dataGridView1.DataBindingComplete += (o, e) =>
    {
        foreach (DataGridViewRow row in dataGridView1.Rows)
            row.HeaderCell.Value = (row.Index + 1).ToString();
    };
 
Share this answer
 
i m zeeshan Ali
simple way to count grid value jus copy and paste your grid last } before you feel heppy

for (int i = 0; i < dgvStonesDetail.Rows.Count; i++)
{
dgvStonesDetail.Rows[counter].Cells[0].Value = (i + 1).ToString();
}
 
Share this answer
 
Comments
CHill60 5-Apr-23 7:24am    
Reason for my downvote. Apart from the question being 9 years old and already resolved, you are referring to a variable counter instead of the variable declared in the loop - i

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900