backcolor in load form
-
hi, i want to change the color of rows with wrong info when i load my form, the info comes from a database, it is checked on error earlier and replaced the value of the cell with "wrong info", now in my load i check all the cells of my datagrid on "wrong info" values if ther is one i want that entire row to color red. i have tried it for one column where there is wrong info, the breakpoint shows me that he does the color changing, but nothing has changed in the view. is it changed back so quickly that i couldnt see it in red? if yes , where woud that code be written? in the defaultview maybe? and how do i sort it then? this is what i wrote in the load from function: lastrow = dataGridView1.Rows.GetLastRow(DataGridViewElementStates.Visible); for (int x = 0; x < lastrow + 1; x++) { string fout = dataGridView1.Rows[x].Cells[3].Value.ToString(); if (fout == "wrong info")//check on wrong info { dataGridView1.Rows[x].Cells[3].Style.BackColor = Color.Red;// color red dataGridView1.Rows[x].Cells[3].Value = "error";// change value to error } } thx
-
hi, i want to change the color of rows with wrong info when i load my form, the info comes from a database, it is checked on error earlier and replaced the value of the cell with "wrong info", now in my load i check all the cells of my datagrid on "wrong info" values if ther is one i want that entire row to color red. i have tried it for one column where there is wrong info, the breakpoint shows me that he does the color changing, but nothing has changed in the view. is it changed back so quickly that i couldnt see it in red? if yes , where woud that code be written? in the defaultview maybe? and how do i sort it then? this is what i wrote in the load from function: lastrow = dataGridView1.Rows.GetLastRow(DataGridViewElementStates.Visible); for (int x = 0; x < lastrow + 1; x++) { string fout = dataGridView1.Rows[x].Cells[3].Value.ToString(); if (fout == "wrong info")//check on wrong info { dataGridView1.Rows[x].Cells[3].Style.BackColor = Color.Red;// color red dataGridView1.Rows[x].Cells[3].Value = "error";// change value to error } } thx
dataGridView1.Rows[x].Cells[3].Style.BackColor = Color.Red;// color red dataGridView1.Rows[x].DefaultCellStyle.BackColor = System.Drawing.Color.Red good luck
Where there is a will,there is a way.
-
dataGridView1.Rows[x].Cells[3].Style.BackColor = Color.Red;// color red dataGridView1.Rows[x].DefaultCellStyle.BackColor = System.Drawing.Color.Red good luck
Where there is a will,there is a way.
thx, i also found something in the meentime :) private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { index = dataGridView1.Rows.GetLastRow(DataGridViewElementStates.Visible); for (int x = 0; x < index + 1; x++) { for (int y = 0; y < colamount; y++) { string fout = dataGridView1.Rows[x].Cells[y].Value.ToString(); if (fout == "foute input!") { dataGridView1.Rows[x].Cells[y].Style.BackColor = Color.Red; } } } } instead of using the load im using addrows, so i dont have to write this when the form loads and when im adding a row :) grz