Change DatagridView row color using condition date. (Function calling a function)

  • Thread starter Thread starter Ruy Santos Moliani
  • Start date Start date
R

Ruy Santos Moliani

Guest
Hello Guys

I have one issue/Question..

Searching on internet about change color on specif rows based on condition, i can get some help.. but cant link one thing with other... so.. here i am....

What i need:

Create a void that will be called on specific time of my code, and inside this void i have a condition:

Call a function to obtain last work_day, and using this date, i need check if in column[2] we have some date before my last work day.

Ok, this part is ok, i can get all this infos and populate on my console... but what i need is change the forecolor of this row to RED... and that was my problem...

i found that this will be done by datagrid_cellformatting... and i create it.. but when i call this create a looping... err... what??

please, someone can help me with this issue?? here are my codes:


Function to compare dates (OK until call paint function)

private void check_late_tickets()
{


int count = start_datagrid.Rows.Count;
Console.Write("Last Work date - " + last_workday(today_date) + "\n");
for (int x = 0; x < count; x++)
{
var z = start_datagrid.Rows[x].Cells[2].Value;
double tmp2 = (Convert.ToDateTime(z) - Convert.ToDateTime(last_workday(today_date))).TotalDays;
if (tmp2 < 0)
{
//Call function to "paint" my row X

}
}
}


Function "Paint":

void start_datagrid__CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
this.start_datagrid.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Red;
}


and yes... i dont know work with EventArgs yet... sorry.

Continue reading...
 
Back
Top