problèmes de formattage de rangée dans un DataGridView
Bonjour,
J'essaie seulement de formatter une rangée selon que a valeure d'une colonne spécifique soit plus grande que 10. J'ai essayé plusieurs méthodes mais je n'y arrive pas.
1ere méthode:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
DataGridViewCellStyle highlightCellStyle = new DataGridViewCellStyle();
highlightCellStyle.BackColor = Color.Green;
highlightCellStyle.ForeColor = Color.Yellow;
foreach (DataGridViewRow row in dataGridView2.Rows)
{
if (Convert.ToDouble(dataGridView2["CAP", row.Index].Value) > 10)
{
foreach (DataGridViewCell cells in row.Cells)
{
cells.Style = highlightCellStyle;
}
}
} |
2e méthode
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
DataGridViewCellStyle highlightCellStyle = new DataGridViewCellStyle();
highlightCellStyle.BackColor = Color.Green;
highlightCellStyle.ForeColor = Color.Yellow;
for (int a = 0; a < dataGridView2.RowCount; a++)
{
for (int b = 0; b < dataGridView2.ColumnCount; b++)
{
if ((b == dataGridView2.Columns["CAP"].Index) && (Convert.ToDouble(dataGridView2[b, a].Value) > 10.0))
{
this.dataGridView1.Rows[a].DefaultCellStyle = highlightCellStyle;
this.dataGridView2.Rows[a].DefaultCellStyle = highlightCellStyle;
this.dataGridView3.Rows[a].DefaultCellStyle = highlightCellStyle;
}
}
} |