-1

我的 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.)

}
4

1 回答 1

0

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

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

于 2020-03-06T17:44:32.713 回答