void 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;
}
}
Private Sub GRD_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles GRD.CellPainting
If (e.ColumnIndex < 0) AndAlso (e.RowIndex >= 0) Then
' This will paint the background
e.PaintBackground(e.CellBounds, False)
' And this will paint your text without the record selectors
e.Paint(e.CellBounds, DataGridViewPaintParts.ContentForeground)
' This avoids grid's own paint handler to execute
e.Handled = True
End If
End Sub
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)