Remplir Combobox

Résolu
cs_simoneo Messages postés 20 Date d'inscription samedi 4 novembre 2006 Statut Membre Dernière intervention 29 juin 2008 - 1 janv. 2008 à 19:08
cs_simoneo Messages postés 20 Date d'inscription samedi 4 novembre 2006 Statut Membre Dernière intervention 29 juin 2008 - 4 janv. 2008 à 23:44
Salut. Je veux savoir comment faire pour remplir un combobox à partir d'un champ du dataset à condition de ne pas avoir des doublons.
Merci d'avance.

2 réponses

cs_simoneo Messages postés 20 Date d'inscription samedi 4 novembre 2006 Statut Membre Dernière intervention 29 juin 2008
4 janv. 2008 à 23:44
Salut greg38bj, Je voudrais que ça soit plus simple que ça, j'ai utlisé une boucle for each.

For Each line As DataRow In ds.Tables("maTable").Rows
            If Not Me.ComboBox1.Items.Contains(line.Item(1)) Then
                Me.ComboBox1.Items.Add(line.Item(1))
            End If
        Next

Merci
3
greg38bj Messages postés 83 Date d'inscription jeudi 11 mars 2004 Statut Membre Dernière intervention 17 novembre 2008
4 janv. 2008 à 17:59
salut
dans un de mes soft, j'avais ces deux fonctions dans un module :

 'Rafraichissement d'un Combobox
    Public Sub RefreshCb(ByVal Combo As ComboBox, ByVal Table As String, ByVal Champs() As String, ByVal Index As Integer)
        Combo.DataSource = AfficherTout(Table)
        Combo.DisplayMember = Champs(Index).ToString
    End Sub

'Fonction de recherche dans la table
 Public Function AfficherTout(ByVal table As String) As DataView
        Dim SourceConnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Nomdelabasededonnée
        SourceOle = New OleDbConnection(SourceConnect)
        Select Case SourceOle.State
            Case ConnectionState.Closed
                SourceOle.Open()
        End Select
        Try
            RequeteSQL = "SELECT * FROM " & table
            Dim DataA As New OleDbDataAdapter(RequeteSQL, SourceOle)
            Dim DataS As New DataSet
            DataA.Fill(DataS, table)
            Dtt = DataS.Tables(table)
            Try 'return incorrect sur du Update
                Return DataS.Tables(table).DefaultView
            Catch ex As Exception
                Return Nothing
            Finally
                Select Case SourceOle.State
                    Case ConnectionState.Open
                        SourceOle.Close()
                        SourceOle.Dispose()
                        SourceOle = Nothing
                        SourceConnect = ""
                End Select
            End Try
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

et dans le formulaire, j'appelais le rafraichissement comme ceci :

RefreshCb(Nomducombobox, Nomdetatable, NomduChamps, Indexduchamps)

en esperant que ça te servira ...
@+
greg38bj
0
Rejoignez-nous