Bonjour tout le monde
J'essai d’intégrer dans ma DataGridView un ComboBoxCell afin d'aider l'utilisateur à choisir un article parmi lesquelles a saisi une partie du Code d'Article , la routine suivante marche très bien pour la 1ere ligne de ma grille , je n'ai pas pu savoir ou ça coince
si quelqu'un pourra m'aider je serai reconnaissant
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 Imports System.Data.OleDb Public Class Dgv Dim cn As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=GestionDepot.mdb") Dim tbl As New DataTable Dim da As OleDbDataAdapter Dim txtCell As New DataGridViewTextBoxCell Dim CmbCell As New DataGridViewComboBoxCell Private Sub Dgv_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load dg.ColumnCount = 2 dg.Columns(1).Width = 300 End Sub Private Sub dg_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellEndEdit If e.ColumnIndex = 0 Then da = New OleDbDataAdapter("select * from Article where CodeArticle like '%" & dg(e.RowIndex, e.ColumnIndex).Value.ToString & "%'", cn) tbl.Clear() da.Fill(tbl) If tbl.Rows.Count > 1 Then CmbCell.DataSource = tbl CmbCell.DisplayMember = "LibelleArticle" Dim colonne As Integer = e.ColumnIndex + 1 Dim ligne As Integer = e.RowIndex dg.Item(colonne, ligne) = CmbCell End If ElseIf e.ColumnIndex = 1 Then Dim Libelle As String Libelle = CmbCell.Value.ToString If TypeOf (dg.Item(e.ColumnIndex, e.RowIndex)) Is DataGridViewComboBoxCell Then dg.Item(e.ColumnIndex, e.RowIndex) = txtCell txtCell.Value = Libelle CmbCell.DataSource = Nothing End If End Sub End Class
Partager