Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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# 如何通过检查值来设置datagird行背景色?C_C# - Fatal编程技术网

C# 如何通过检查值来设置datagird行背景色?C

C# 如何通过检查值来设置datagird行背景色?C,c#,C#,我的c项目中有一个数据网格。在该数据网格中,有一个名为“Current情境”的列。在该列中有两个值。。一个值已排序,另一个值未排序 这是我想做的。。。。我想将数据网格行背景颜色更改为红色,前提是“当前情况”列值等于ORDERED 代码是什么 private void frmVehicales_Load(object sender, EventArgs e) { Form1.dtSet.Tables.Clear(); dtgVehicals.Rows.Clear(); dt

我的c项目中有一个数据网格。在该数据网格中,有一个名为“Current情境”的列。在该列中有两个值。。一个值已排序,另一个值未排序

这是我想做的。。。。我想将数据网格行背景颜色更改为红色,前提是“当前情况”列值等于ORDERED

代码是什么

private void frmVehicales_Load(object sender, EventArgs e)
{
    Form1.dtSet.Tables.Clear();
    dtgVehicals.Rows.Clear();
    dtgVehicals.Refresh();

    Form1.con.Open();
    Form1.dtAdapter = new System.Data.SqlClient.SqlDataAdapter("SELECT * FROM AyuboVehicales", Form1.con);
    Form1.dtAdapter.Fill(Form1.dtSet, "AyuboVehicales");
    Form1.con.Close();

    int currentRow = 0;
    int rowCount = Form1.dtSet.Tables["AyuboVehicales"].Rows.Count;

    while (currentRow < rowCount)
    {
        string Vbrand = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[1].ToString();
        string Vname = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[2].ToString();
        string Vnumber = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[3].ToString();
        string Vtype = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[4].ToString();
        string Vcategory = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[5].ToString();
        string OneDchrg = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[6].ToString();
        string OneWchrg = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[7].ToString();
        string OneMchrg = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[8].ToString();
        string DriverCrg = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[9].ToString();
        string PicPath = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[10].ToString();
        string situation = Form1.dtSet.Tables["AyuboVehicales"].Rows[currentRow].ItemArray[11].ToString();

        dtgVehicals.Rows.Add(Vbrand, Vname, Vnumber, Vtype, Vcategory, OneDchrg, OneWchrg, OneMchrg, DriverCrg, PicPath, situation);
        currentRow++;
    }
    ////CODE WILL PUT HERE
    if(dtgVehicals.Rows.)

}
如果情况==有序 dtgVehicles.BackColor=Color.Red


您必须使用System.Drawing才能工作。

使用RowPrePaint事件您能告诉我如何对这种情况进行编码吗。。?