Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于单元格值更改DataGridView的行颜色_C#_.net_Datagridview_Datasource_Bindingsource - Fatal编程技术网

C# 基于单元格值更改DataGridView的行颜色

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

我有两列数据Gridview,即文件名和状态

 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;
            }
        }
    }
可能重复的