I've a project compiled for .net 3.5. In the project there is a form with a DataGridView. In CellPainting I'am adding row numbers in row header:

private void dataGridView1_CellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
    if (e.ColumnIndex == -1)
       e.PaintBackground(e.ClipBounds, true);
       using (StringFormat st = new StringFormat())
            st.Alignment = StringAlignment.Center;
            st.LineAlignment = StringAlignment.Center;
            e.Graphics.DrawString(Convert.ToString(e.FormattedValue), e.CellStyle.Font, Brushes.Black, e.CellBounds, st);
            e.Handled = true;

When I test it on win8 where .net 3.5 is enabled, everything works ok. If there is .net3.5 disabled and only 4.5 is enabled, this is working pretty slow. Row numbers in row headers flicker and other forms are not refreshed well. When row headers are hidden, Form works ok, and the application is quite fast. Is there a way to prevent the slowness of the application when headers are visible? Any idea why this code isn't working?(beside incompatibility of .net versions)

So you are trying to write a number into the row headers?

Have you tried items like this?

dataGridView1.RowHeadersDefaultCellStyle.Font = new Font("Arial", 50); 
dataGridView1.RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

You can also do items like backcolor. And then if you want to set the text you can use this piece of code

dataGridView1.Rows[index].HeaderCell.Value = "";
This article has been dead for over six months. Start a new discussion instead.