【发布时间】:2021-04-10 10:39:51
【问题描述】:
我正在从列表中填充 DataGridView。在其中一列中,我需要能够使用 ColorDialog 更改单个单元格的 BackColor。
我这样做:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) {
if (e.ColumnIndex == 2) {
ColorDialog cd1 = new ColorDialog();
if (cd1.ShowDialog() == DialogResult.OK) {
Color color = cd1.Color;
dataGridView1.Rows[e.RowIndex].Cells[2].Style.BackColor = color;
}
}
}
但是,BackColor 不会立即出现,只有在鼠标单击 DataGrid 后才会出现。
我试过了:
dataGridView1.Update();
dataGridView1.Refresh();
似乎没有任何效果。
有什么方法可以让单元格在颜色改变后自动刷新?
【问题讨论】:
标签: c# datagridview