Remplire une dropdownlist

meryem -  
Kalissi Messages postés 221 Statut Membre -
bonjour,
je sais comment remplire une dropdownlist depuis SQL mais ce que je cherche c'est comment y afficher l'element que je veux moi
merci

3 réponses

  1. Kalissi Messages postés 221 Statut Membre 20
     
    Bonjour'

    Exemple :

    Soit un ComboBox (cbxListeItem) de liste de nom.



    Private Sub btnRechercheIndex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRechercheIndex.Click

    Dim Indice As Int32 = RechercheIndice("Claude")
    ' TextBox pour afficher l'indice
    Me.tbx_Index.Text = Indice.ToString
    'Positionnement du ComboBox sur l'élément trouvé
    Me.cbxListeItem.SelectedIndex = (Indice)

    End Sub

    Private Function RechercheIndice(ByVal pPrenom As String) As Int32

    Dim Indice As Int32 = 0
    Dim Limite As Int32 = Me.cbxListeItem.Items.Count - 1
    For Boucle As Int32 = 0 To Limite
    If (cbxListeItem.Items.Item(Boucle) Is pPrenom) Then
    Indice = Boucle
    Exit For
    End If
    Next

    Return Indice

    End Function



    Testé sous VB2008

    K
    0
  2. Kalissi Messages postés 221 Statut Membre 20
     
    Bonjour,

    Ne connaissez-vous pas :

    https://www.developerfusion.com/tools/convert/vb-to-csharp/


    private void btnRechercheIndex_Click(System.Object sender, System.EventArgs e)
    {
    Int32 Indice = RechercheIndice("Claude");
    // TextBox pour afficher l'indice
    this.tbx_Index.Text = Indice.ToString();
    //Positionnement du ComboBox sur l'élément trouvé
    this.cbxListeItem.SelectedIndex = (Indice);

    }

    private Int32 RechercheIndice(string pPrenom)
    {

    Int32 Indice = 0;
    Int32 Limite = this.cbxListeItem.Items.Count - 1;
    for (Int32 Boucle = 0; Boucle <= Limite; Boucle++) {
    if ((object.ReferenceEquals(cbxListeItem.Items.Item(Boucle), pPrenom))) {
    Indice = Boucle;
    break; // TODO: might not be correct. Was : Exit For
    }
    }

    return Indice;

    }

    non testé !

    K
    0