Bonjour,
actuellement je colore les lignes de mon datagridview issu d'une base de donnée avec RowPrePaint, cela fonctionne bien ainsi je color de deux façon différente selon le texte qui se trouve dans la colonne n°2 qui vaut soit 'direct' soit 'multiple', voila le code :
Mais maintenant je souhaiterais aussi colorier les lignes au rouge qui contiennent la valeurs 1 dans un autre numéro de colonne (la N°11) ainsi voila mon code a présent :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 Private Sub DataGridView1_RowPrePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex) Dim cellValue As Object = row.Cells(2).Value 'le numero 2 correspond au champ type If cellValue IsNot Nothing AndAlso cellValue.ToString.StartsWith("direct") Then row.DefaultCellStyle.BackColor = Color.LightGreen ElseIf cellValue IsNot Nothing AndAlso cellValue.ToString.StartsWith("multiple") Then row.DefaultCellStyle.BackColor = Color.Tan End If End Sub
Mais rien ne se passe, les lignes contenant 1 dans la colonne portant l'index n°11 ne passe pas au rouge, ainsi je me demande si l'on peu mettre dans RowPrePaint 2 conditions sur 2 colonne différentes ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 Private Sub DataGridView1_RowPrePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex) Dim cellValue As Object = row.Cells(2).Value 'le numero 2 correspond au champ type If cellValue IsNot Nothing AndAlso cellValue.ToString.StartsWith("direct") Then row.DefaultCellStyle.BackColor = Color.LightGreen ElseIf cellValue IsNot Nothing AndAlso cellValue.ToString.StartsWith("multiple") Then row.DefaultCellStyle.BackColor = Color.Tan End If Dim row2 As DataGridViewRow = DataGridView1.Rows(e.RowIndex) Dim cellValue2 As Object = row2.Cells(11).Value 'le numero 11 correspond au champ statut If cellValue2 IsNot Nothing AndAlso cellValue.ToString.StartsWith("1") Then row2.DefaultCellStyle.BackColor = Color.Red End If End Sub
Partager