c# - 如何更改数据网格特定行的颜色

标签 c# .net

我要将数据表绑定(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/

相关文章:

c# - 在 PropertyGrid 中动态设置属性的只读属性

c# - 如何将应用程序设置导出到可移植文件中? [C#]

c# - 在启用 VirtualMode 的情况下在 ListView 中聚焦一个项目

c# - 用于频繁读取和罕见写入操作的并发集合 (.NET)

使用按钮回发而不是使用 POST 的 C# Webform 文件上传

c# - 将音频播放到.net中的非默认播放设备

Node : require vs constructor injection 中的 Javascript 依赖注入(inject)和 DIP

.net - .NET 中的弱事件?

c# - 批量更新字典内多个记录的属性 (VB.NET/C#)

c# - Entity Framework 的额外属性不由 DbContext.Database.SqlQuery 填充