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;
}
}
}