Bonjour,

Afin de pouvoir afficher des étoiles dans un DataGridViewComboBoxCell, voici le code utiliser :


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
  Private Sub DGW_Historique_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DGW_Historique.CellPainting
        If e.ColumnIndex < 0 OrElse e.RowIndex < 0 Then Exit Sub
        Dim CelluleQualite As DataGridViewComboBoxCell = Nothing
 
        If e.ColumnIndex = Colonne_Qualite.Index Then
            CelluleQualite = DirectCast(DGW_Historique.Rows(e.RowIndex).Cells(e.ColumnIndex), DataGridViewComboBoxCell)
            If IsNothing(CelluleQualite) OrElse String.IsNullOrWhiteSpace(CelluleQualite.Value.ToString) Then Exit Sub
            With e
                .PaintBackground(e.ClipBounds, True)
                .PaintContent(e.ClipBounds)
                .Graphics.DrawImage(CType(e.Value, Image), New Rectangle(e.CellBounds.X, e.CellBounds.Y, 60, 20))
            End With
            e.Handled = True
        End If
    End Sub
 
 
 
    Private Sub DGW_Historique_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DGW_Historique.EditingControlShowing
        If TypeOf e.Control Is ComboBox Then
            If DGW_Historique.CurrentCell.ColumnIndex = Colonne_Qualite.Index Then
                With DirectCast(e.Control, ComboBox)
                    .Size = New Size(60, 20)
                    .ItemHeight = 20
                    .DropDownHeight = 80
                    .DrawMode = DrawMode.OwnerDrawFixed
                    Try
                        RemoveHandler .DrawItem, AddressOf GridView_IconDropDown_DrawItem
                    Catch
                    End Try
 
                    AddHandler .DrawItem, AddressOf GridView_IconDropDown_DrawItem
                End With
            End If
        End If
    End Sub
 
 
    Private Sub GridView_IconDropDown_DrawItem(sender As Object, e As DrawItemEventArgs)
        Dim CurrentGraphic As Graphics = e.Graphics
        Dim LeComboBox As ComboBox = CType(sender, ComboBox)
        If e.Index >= 0 AndAlso Not IsNothing(LeComboBox.Items(e.Index)) Then
            CurrentGraphic.DrawImage(CType(LeComboBox.Items(e.Index), Image), New Rectangle(e.Bounds.Left, e.Bounds.Top, 40, 40))
        End If
    End Sub

Le code ci-dessous affiche les images. L'affichage n'est pas très propre, néanmoins le problème n'est pas là Lorsque je sélectionne l'image depuis le DataGridViewComboBoxCell l'application ne réagi plus, cependant l'application ne plante pas pour autant.

Je vous avoue que je suis un peu dans le brouillard. Je ne sais pas du tout quoi faire.

Si quelqu'un à une idée, merci d'avance.