Bonjour

Aprés plusieurs jours de reccherche dans sur le net, j'ai pas pu trouver l'erreur dans mon code, alors je m'adresse a vous si vous pouvez m'aider

mon sujet est:

j'ai un datagridview "DataGListe" lié à une datatable

j'ai ajouté au DataGListe une colonne de type DataGridViewComboBoxColumn


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
Sub AjouterColonne()
 
                    Dim ComboColonne As New DataGridViewComboBoxColumn
                    With Me.DataGListe
                        .Columns.Insert(4, ComboColonne)
                        With .Columns(4)
                            .Width = 200
                            .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
                            .Name = "Reglement"
                            .ReadOnly = False
                        End With
                   End With
 
                    Dim cb As New DataGridViewComboBoxCell
                    cb.Items.Add("1")
                    cb.Items.Add("2")
                    Me.DataGListe.Rows.Item(0).Cells("Reglement") = New DataGridViewComboBoxCell()
                    Me.DataGListe.Rows.Item(0).Cells("Reglement") = cb
                    Me.DataGListe.Rows.Item(0).Cells("Reglement").Value = cb.Items(0).ToString
                    Me.DataGListe.Columns(0).ReadOnly = True
 
End Sub
 
Private Sub FrmListe_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AjouterColonne()
End Sub
Puis dans l'evenement CellClick de mon datagridview j'ai mis

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
Private Sub DataGListe_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGListe.CellClick
 
                If Me.DataGListe.Columns(e.ColumnIndex).Name = "Reglement" Then
                    Me.DataGListe.BeginEdit(True)
                    If DataGListe.Rows(e.RowIndex).Cells("Reglement").Selected = True Then
                        DirectCast(Me.DataGListe.EditingControl, DataGridViewComboBoxEditingControl).DroppedDown = True
                    End If
                EndIf
 
End Sub
mais j'ai toujours l'erreur
La référence d'objet n'est pas définie à une instance d'un objet.
merci