Bonjour,
j'ai une datagridview qui se trouve dans un UserControl.
J'utilise l'événement Cellpainting pour "peindre" une image sur un bouton et l'événement RowPostPaint pour changer la couleur du texte de la ligne si une cellule "Supprime" est cochée.
Cela fonctionne bien mais je ne comprend pas pourquoi les événements boucle à l'infini. Sur mon PC je ne vois rien de particulier mais en mode Debug (VS 2008) je vois bien que cela boucle. Chez mon client (qui a plus de données en production), cela fait sapin de noel. cela ne s'arrête pas de clignoter.
Avez-vous une idée de ce qui se passe ?
Pour information, j'appelle ma fonction "Init" de mon userControl après l'initialisation de mon formulaire principal. (cette fonction permet de charger les données dans la DataGridView depuis une DataTable).
Init :
Evénements :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3bdsContacts.DataSource = ppDtContacts 'DataTable' dgvListe.DataSource = bdsContacts
Merci pour votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 Private Sub dgvListe_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvListe.CellClick If e.RowIndex >= 0 Then 'Ouvre la fiche du contact' If e.ColumnIndex = dgvListe.Columns(KColBouton).Index Then OuvrirFiche(e.RowIndex) End If 'Appel le contact' If e.ColumnIndex = dgvListe.Columns(KColAppel).Index Then AppelerNumero() End If End If End Sub Private Sub dgvListe_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvListe.CellDoubleClick 'Ouvre la fiche du contact ' If e.RowIndex >= 0 Then OuvrirFiche(e.RowIndex) End Sub Private Sub dgvListe_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles dgvListe.CellPainting If e.RowIndex >= 0 AndAlso (e.ColumnIndex = dgvListe.Columns(KColBouton).Index OrElse e.ColumnIndex = dgvListe.Columns(KColAppel).Index) Then 'Affiche la loupe dans le bouton' If e.ColumnIndex = dgvListe.Columns(KColBouton).Index Then e.Paint(e.CellBounds, DataGridViewPaintParts.All) e.Graphics.DrawImage(My.Resources.resImages.loupe, e.CellBounds.Left + 3, e.CellBounds.Top + 3) e.Handled = True End If 'Affiche le téléphone dans le bouton' If e.ColumnIndex = dgvListe.Columns(KColAppel).Index Then e.Paint(e.CellBounds, DataGridViewPaintParts.All) e.Graphics.DrawImage(My.Resources.resImages.appel, e.CellBounds.Left + 3, e.CellBounds.Top + 3) e.Handled = True End If End If End Sub Private Sub dgvListe_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgvListe.RowPostPaint If e.RowIndex >= 0 Then Dim dgcCellule As DataGridViewCell = dgvListe.Rows(e.RowIndex).Cells(KColSupprime) 'Grise la ligne si le contact est inactif' If dgcCellule.Value IsNot Nothing AndAlso Not IsDBNull(dgcCellule.Value) AndAlso ClsConvert.ObjectToBoolean(dgcCellule.Value) = True Then dgvListe.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Silver End If End If End Sub
Partager