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 :

l'élément suivant d'un combobox


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre très actif
    Homme Profil pro
    génie logiciel
    Inscrit en
    Mars 2012
    Messages
    113
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : génie logiciel

    Informations forums :
    Inscription : Mars 2012
    Messages : 113
    Par défaut l'élément suivant d'un combobox
    Bonjour,
    j' ai un combobox que je remplis à partir d'une bd sqlserver et dont je récupère la valeur sélectionnée lors d'un insert.
    jusque là tout se passe bien à merveille mais je voudrai que quand l'insertion se fait en succès le combobox passe automatiquement à l'élément suivant qui s'y trouve.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     Try
                            'insertion dans le table compteur
                            com = New SqlCommand("insert into COMPTEURS(N_ORD_ECO,SOUS_QUART,CIL,QUART,NOM_CLT,AV_ACC,PORTE,RUE,N_CPT_DEPO,N_SERIE,DER_IND_LU,TP_CAL,MAR_DEPO,N_CPT_POS,IND_DEPO,DATE_DEPO,CAL_POS,MAR_POS,AG) values('" & ComboBox1.SelectedItem.ToString & "','" & Replace(TextBox1.Text, "'", " ", 1, vbTextCompare) & "','" & Val(TextBox2.Text) & "','" & Replace(TextBox3.Text, "'", " ", 1, vbTextCompare) & "','" & Replace(TextBox4.Text, "'", " ", 1, vbTextCompare) & "','" & Replace(TextBox5.Text, "'", " ", 1, vbTextCompare) & "','" & Val(TextBox6.Text) & "','" & Replace(TextBox7.Text, "'", " ", 1, vbTextCompare) & "','" & Val(TextBox8.Text) & "','" & Val(TextBox9.Text) & "','" & Val(TextBox10.Text) & "','" & Val(TextBox11.Text) & "','" & TextBox12.Text & "','" & Val(TextBox13.Text) & "','" & Val(TextBox14.Text) & "','" & d & "','" & Val(TextBox16.Text) & "','" & TextBox17.Text & "','" & ComboBox3.SelectedItem & "');", con)
                            com.ExecuteNonQuery()
                            MsgBox("Compteur ajouté avec succés", MsgBoxStyle.OkOnly)
                            TextBox13.Text = ""
                            TextBox14.Text = ""
                            MaskedTextBox1.Text = ""
     
                        Catch ex As Exception
                            MsgBox("Erreur d'insertion des données:" & ex.ToString)
                        End Try
                    End If

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

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 50
    Par défaut
    il te faut récuperer l'index de l'élement sélectionné lors de clic sur le bouton d'ajout.
    Voici un exemple.
    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
     Try
                            'insertion dans le table compteur
    dim index as integer=combobox.selectedIndex
                            com = New SqlCommand("insert into COMPTEURS(N_ORD_ECO,SOUS_QUART,CIL,QUART,NOM_CLT,AV_ACC,PORTE,RUE,N_CPT_DEPO,N_SERIE,DER_IND_LU,TP_CAL,MAR_DEPO,N_CPT_POS,IND_DEPO,DATE_DEPO,CAL_POS,MAR_POS,AG) values('" & ComboBox1.SelectedItem.ToString & "','" & Replace(TextBox1.Text, "'", " ", 1, vbTextCompare) & "','" & Val(TextBox2.Text) & "','" & Replace(TextBox3.Text, "'", " ", 1, vbTextCompare) & "','" & Replace(TextBox4.Text, "'", " ", 1, vbTextCompare) & "','" & Replace(TextBox5.Text, "'", " ", 1, vbTextCompare) & "','" & Val(TextBox6.Text) & "','" & Replace(TextBox7.Text, "'", " ", 1, vbTextCompare) & "','" & Val(TextBox8.Text) & "','" & Val(TextBox9.Text) & "','" & Val(TextBox10.Text) & "','" & Val(TextBox11.Text) & "','" & TextBox12.Text & "','" & Val(TextBox13.Text) & "','" & Val(TextBox14.Text) & "','" & d & "','" & Val(TextBox16.Text) & "','" & TextBox17.Text & "','" & ComboBox3.SelectedItem & "');", con)
                            com.ExecuteNonQuery()
                            MsgBox("Compteur ajouté avec succés", MsgBoxStyle.OkOnly)
                            TextBox13.Text = ""
                            TextBox14.Text = ""
                            MaskedTextBox1.Text = ""
    
     combobox.selectedIndex=index+1
                        Catch ex As Exception
                            MsgBox("Erreur d'insertion des données:" & ex.ToString)
                        End Try
                    End If
    Bon chance.

  3. #3
    Membre Expert Avatar de _Ez3kiel
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2013
    Messages
    836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Janvier 2013
    Messages : 836
    Par défaut
    Ou si tu n'as pas l'utilité -pour le moment- de stocker l'index, et que tu veux juste passer à l'index suivant après l'INSERT ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     Try
                            'insertion dans le table compteur
                            com = New SqlCommand("insert into COMPTEURS(N_ORD_ECO,SOUS_QUART,CIL,QUART,NOM_CLT,AV_ACC,PORTE,RUE,N_CPT_DEPO,N_SERIE,DER_IND_LU,TP_CAL,MAR_DEPO,N_CPT_POS,IND_DEPO,DATE_DEPO,CAL_POS,MAR_POS,AG) values('" & ComboBox1.SelectedItem.ToString & "','" & Replace(TextBox1.Text, "'", " ", 1, vbTextCompare) & "','" & Val(TextBox2.Text) & "','" & Replace(TextBox3.Text, "'", " ", 1, vbTextCompare) & "','" & Replace(TextBox4.Text, "'", " ", 1, vbTextCompare) & "','" & Replace(TextBox5.Text, "'", " ", 1, vbTextCompare) & "','" & Val(TextBox6.Text) & "','" & Replace(TextBox7.Text, "'", " ", 1, vbTextCompare) & "','" & Val(TextBox8.Text) & "','" & Val(TextBox9.Text) & "','" & Val(TextBox10.Text) & "','" & Val(TextBox11.Text) & "','" & TextBox12.Text & "','" & Val(TextBox13.Text) & "','" & Val(TextBox14.Text) & "','" & d & "','" & Val(TextBox16.Text) & "','" & TextBox17.Text & "','" & ComboBox3.SelectedItem & "');", con)
                            com.ExecuteNonQuery()
                            MsgBox("Compteur ajouté avec succés", MsgBoxStyle.OkOnly)
                            TextBox13.Text = ""
                            TextBox14.Text = ""
                            MaskedTextBox1.Text = ""
                            ComboBoxInconnu.SelectedIndex += 1 
     
                        Catch ex As Exception
                            MsgBox("Erreur d'insertion des données:" & ex.ToString)
                        End Try
                    End If

  4. #4
    Modérateur
    Avatar de Sankasssss
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2006
    Messages
    1 842
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 842
    Par défaut
    Attention, vous oubliez de tester si vous êtes au dernier item avant de faire le +1
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    If ComboBox1.Items.Count > ComboBox1.SelectedIndex Then ComboBox1.SelectedIndex += 1
    Si vous ne le faite pas, vous allez lever une ArgumentOutOfRangeException qui entrera dans le catch et fera croire à une "Erreur d'insertion des données"

  5. #5
    Membre Expert Avatar de _Ez3kiel
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2013
    Messages
    836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Janvier 2013
    Messages : 836
    Par défaut
    Mea Culpa, merci pour la précision.

Discussions similaires

  1. L'élément suivant dans la lecture d'une DataTable
    Par zooffy dans le forum ASP.NET
    Réponses: 4
    Dernier message: 21/07/2008, 14h33
  2. élément unique dans une combobox
    Par zandru dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 15/07/2008, 11h45
  3. Ajouter un élément TExtBox dans un combobox
    Par programaniac dans le forum Windows Forms
    Réponses: 4
    Dernier message: 05/03/2008, 18h36
  4. [Tableaux] Passer à l'élément suivant
    Par cyrill.gremaud dans le forum Langage
    Réponses: 2
    Dernier message: 13/09/2006, 10h31
  5. [focus] Passer le focus à l'élément suivant
    Par FrankOVD dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 12/05/2006, 22h02

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