1
我得到的代码是将行的所有单元格着色,但是我需要着色某个/当前单元格。如何给DataGridView中的当前单元格着色
它是如何做到的?
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex > -1)
{
ThemeColorView tc = (dataGridView1.Rows[e.RowIndex].DataBoundItem as ThemeColorView);
if (tc != null)
{
Color c = Color.FromName(tc.ColorType.Trim());
Brush b = new SolidBrush(c);
// I know something shoud be changed here ;)
e.Graphics.FillRectangle(b, e.CellBounds);
e.PaintContent(e.ClipBounds);
e.Handled = true;
}
}
}