Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dataGridView2_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)//I have used this event
- string unit = Convert.ToString(dataGridView2.Columns["exam"]);//One of my datagridview
- //column name is exam and in that column cells will be unit1 or unit2 or unit3 or unit 4 or quarterly or halfyearly or yearly
- if (unit == "Unit 1" ||unit == "Unit1" || unit == "Unit2" || unit == "Unit3" || unit == "Unit4")
- {
- for (int i = 0; i < dataGridView2.Rows.Count; i++)
- {
- for (int j = 7; j < dataGridView2.Rows[i].Cells.Count; j++)
- {
- if (Convert.ToInt32(dataGridView2.Rows[i].Cells[j].Value) < 13)
- {
- dataGridView2.Rows[i].Cells[j].Style.ForeColor = Color.Red;
- }
- else
- {
- dataGridView2.Rows[i].Cells[j].Style.ForeColor = Color.Green;
- }
- }
- }
- }
- else
- {
- for (int i = 0; i < dataGridView2.Rows.Count; i++)
- {
- for (int j = 7; j < dataGridView2.Rows[i].Cells.Count; j++)
- {
- if (Convert.ToInt32(dataGridView2.Rows[i].Cells[j].Value) < 35 )
- dataGridView2.Rows[i].Cells[j].Style.ForeColor = Color.Red;
- else
- dataGridView2.Rows[i].Cells[j].Style.ForeColor = Color.Green;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement