Just hanlding the CellPainting and do something like this:
Code Block
dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == -1 && e.RowIndex > -1)
{
e.PaintBackground(e.CellBounds,true);
using (SolidBrush br = new SolidBrush(Color.Black))
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString(e.RowIndex.ToString(),
e.CellStyle.Font, br, e.CellBounds, sf);
}
e.Handled = true;
}
}
|