C# 基于单元格值更改DataGridView的行颜色
我有两列数据Gridview,即文件名和状态C# 基于单元格值更改DataGridView的行颜色,c#,.net,datagridview,datasource,bindingsource,C#,.net,Datagridview,Datasource,Bindingsource,我有两列数据Gridview,即文件名和状态 var bs = new BindingSourceAsync(); bs.DataSource = data; dataGridView4.DataSource = bs; 使用async await方法更新状态列的值。当状态值无效时,我需要将相应的行颜色更改为红色和绿色(如果有效) 为此,我尝试挂接DataGridView的CellValueChanged事件 dataGridView4.CellValueChanged += DataG
var bs = new BindingSourceAsync();
bs.DataSource = data;
dataGridView4.DataSource = bs;
使用async await方法更新状态列的值。当状态值无效时,我需要将相应的行颜色更改为红色和绿色(如果有效)
为此,我尝试挂接DataGridView的CellValueChanged事件
dataGridView4.CellValueChanged += DataGridView4_CellValueChanged;
但事件从未被触发。我如何解决此问题。请提供建议 是,在gridview的行数据绑定中
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
// check if it is the DataRow not the header row
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Cell[1] is the cell contain the value for the condition
if (Convert.ToInt16(e.Row.Cells[1].Text) < 10)
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Yellow;
e.Row.Cells[1].BackColor = System.Drawing.Color.Yellow;
}
else if (Convert.ToInt16(e.Row.Cells[1].Text) < 30)
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Blue;
e.Row.Cells[1].BackColor = System.Drawing.Color.Blue;
}
}
}
可能重复的