我要将数据表绑定(bind)到数据网格 我只想根据数据表行上的值更改特定数据网格行的颜色。我需要它的 c#/.net 代码
最佳答案
类似于:
this.dataGridView1.Rows[RowIndex].DefaultCellStyle.BackColor = Color.Yellow;
或者如果你想在鼠标移动事件上使用它
private void DataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
dataGridView1[e.ColumnIndex, e.RowIndex].Style.SelectionBackColor = Color.Red;
}
private void DataGridView_CellLeave1(object sender, DataGridViewCellEventArgs e)
{
dataGridView1[e.ColumnIndex, e.RowIndex].Style.SelectionBackColor = Color.Blue;
}
此外,Change individual DataGridView row colors based on column value可能有帮助。
关于c# - 如何更改数据网格特定行的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3952254/