IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

select items combobox dans datagrid


Sujet :

VB.NET

  1. #1
    Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2010
    Messages
    97
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2010
    Messages : 97
    Points : 48
    Points
    48
    Par défaut select items combobox dans datagrid
    Bonjour ,

    je possède une colonne de type COMBOBOX dans une DATAGRID , et j'arrive à le remplir correctement à partir d'un Datareader , mais je ne sais pas comment afficher des données sur d'autres cellules du datagrid à partir du selectedvalue du combobox ..

    le code pour charger le combobox :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    cmd.CommandText = "select designationArticle,fabricantArticle from Article"
            Dim Dgvc As New DataGridViewComboBoxCell
            dr = cmd.ExecuteReader
            If dr.HasRows Then
                While dr.Read
                    Dgvc.Items.Add(dr(0) & " " & dr(1))
                End While
                DataGridView1.Item(1, 0) = Dgvc
            End If

    le code pour afficher les valeurs suite à une selection d'un item du combobox :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
            If DataGridView1.CurrentCell.ColumnIndex = 1 Then
                Dim comboBox As ComboBox = CType(e.Control, ComboBox)
                If (comboBox IsNot Nothing) Then
                    'Remove an existing event-handler
                    RemoveHandler comboBox.SelectedIndexChanged, New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
                    'Add the event handler. 
                    AddHandler comboBox.SelectedIndexChanged, New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
                End If
            End If      
        End Sub
    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
     Private Sub ComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            Dim comboBox As ComboBox = CType(sender, ComboBox)
            Dim dr As SqlDataReader
            Dim cmd As New SqlCommand
            cn.Open()
            cmd.Connection = cn
            'Display selected value
            MsgBox("ProgramID: " & comboBox.SelectedItem.ToString)
            cmd.CommandText = "select idArticle,prix1 from ARTICLE where designationArticle like '" & comboBox.SelectedItem.ToString & "%'"
            dr = cmd.ExecuteReader
                If dr.HasRows Then
                    While dr.Read
                    DataGridView1.CurrentRow.Cells(0).Value = dr(0)
                    DataGridView1.CurrentRow.Cells(3).Value = dr(1)
                    End While
                End If
            dr.Close()
            cn.Close()
        End Sub

    Merci

  2. #2
    Membre du Club
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2010
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mars 2010
    Messages : 71
    Points : 47
    Points
    47
    Par défaut
    Essayer de remplacer comboBox.SelectedItem.ToString Par comboBox.text

Discussions similaires

  1. Réponses: 4
    Dernier message: 15/04/2010, 10h20
  2. combobox dans datagrid
    Par sky88 dans le forum VB.NET
    Réponses: 2
    Dernier message: 29/04/2009, 16h06
  3. Combobox dans datagrid et liaison
    Par Plantadonf dans le forum VB.NET
    Réponses: 4
    Dernier message: 09/03/2007, 15h33
  4. ComboBox dans DataGrid
    Par the big ben 5 dans le forum Composants VCL
    Réponses: 5
    Dernier message: 20/12/2005, 15h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo