I have a data grid in my c# project. in that data grid there is a column named 'CurrentSituation'. In that column there are two values.. one value is "ORDERED" and the other is "NOTORDERED"..
Here is i want to do.... I want to change data grid row background color to red, if 'CurrentSituation' column value is equal to "ORDERED".
What is the code for that..???
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;
You have to use System.Drawing for this to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.