繁体   English   中英

如何通过检查值来设置数据网格行背景颜色? C#

[英]How set datagird row background color, by checking a value? c#

我的 c# 项目中有一个数据网格。 在该数据网格中有一个名为“CurrentSituation”的列。 在该列中有两个值..一个值是“ORDERED”,另一个是“NOTORDERED”..

这是我想要做的...。如果“CurrentSituation”列值等于“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.)

}

if (situation == "ORDERED") dtgVehicles.BackColor = Color.Red;

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM