Msgbox listbox

rsx602 Messages postés 140 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 28 août 2014 - 26 févr. 2014 à 21:55
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 - 27 févr. 2014 à 16:01
Bonjour,

Je cherche un code qui regarde dans le listbox si exemple "allo" existe. Si oui il le sort en msgbox. S'il y a plus d'un allo (allo 2 , allo 3) il dois également les sortir. Aussi si je fait une recherche "2" il dois me sortir également le allo 2. j'espere ne pas etre trop mélangeant :P

merci,

6 réponses

cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
26 févr. 2014 à 22:29
Salut
Il n'y a pas de code tout pret

tu as besoin d'une une list of string pour proceder au recherche
http://msdn.microsoft.com/fr-fr/library/6sh2ey19(v=vs.110).aspx#fbid=-gJJW8JBm6j
0
rsx602 Messages postés 140 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 28 août 2014
26 févr. 2014 à 22:41
        If searchstring <> String.Empty Then
            ' Find the item in the list and store the index to the item. 
            Dim index As Integer = ListBox1.FindString(searchstring)
            ' Determine if a valid index is returned. Select the item if it is valid. 
            If index <> -1 Then
                ListBox1.SetSelected(index, True)
                MsgBox("Name : " & ListBox1.SelectedItem)
            Else
                MessageBox.Show("The search string did not match any names")
            End If
        End If


J'ai deja sa qui trouve si "allo" existe mais si il y a en a plusieur "allo 2" , "allo 3" il ne me les sort pas. Ainsi si je cherche pour "3" il ne me sort pas le "allo 3"
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
26 févr. 2014 à 23:33
Private Sub testlistbox(ByVal searchstring As String)
Dim num As Integer

If Integer.TryParse(searchstring, num) Then
For iter As Integer = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(iter).ToString.StartsWith("allo") AndAlso ListBox1.Items(iter).ToString.Contains(searchstring) Then
ListBox1.SetSelected(iter, True)
MessageBox.Show("Name : " & ListBox1.SelectedItem.ToString)
End If
Next
Else
For iter As Integer = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(iter).ToString.StartsWith(searchstring) Then
ListBox1.SetSelected(iter, True)
MessageBox.Show("Name : " & ListBox1.SelectedItem.ToString)
End If
Next
End If

End Sub
0
rsx602 Messages postés 140 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 28 août 2014
27 févr. 2014 à 01:46
http://i.imgur.com/slVlKT6.png , sa me sort toujours juste un nom et non les 3 :( aussi si je cherche par nom de famille cest raté sa me sort rien =[. Merci de ton aide !!
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
27 févr. 2014 à 09:09
Bonjour,

Essaie ceci:

  Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim listLength As Integer = (ListBox1.Items.Count - 1)
Dim i As Integer
Dim listString As String
If TextBox1.TextLength <= 2 Then
MessageBox.Show("Vous devez saisir 3 caractères minimum!", "Sélection", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
For i = 0 To listLength
listString = CStr(ListBox1.Items.Item(i))
If CBool(InStr(listString.ToLower, TextBox1.Text.ToLower)) Then
ListBox1.SelectedItems.Add(listString)
MessageBox.Show("Nom : " & ListBox1.SelectedItem.ToString, "Recherche", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Next
listString = Nothing
End Sub

0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
27 févr. 2014 à 10:03
Bien il faut d'abord savoir ce qu'on veut avant de coder
et pas coder et ensuite ajouter ou modifier les demandes
tu veux procéder au recherche par prénom ou par nom ou par
numéro ?

 Private Sub testlistbox(Optional ByVal prenom As String = Nothing, Optional ByVal nom As String = Nothing, Optional ByVal num As String = Nothing)

Dim found As Boolean = False
Dim searchname As String = String.Empty
Dim foundstr As String = String.Empty
Dim numero As Integer
If prenom <> String.Empty Then
searchname = prenom
ElseIf nom <> String.Empty Then
searchname = nom
End If
'recherche le nom ou prenom selon le numéro
If num <> String.Empty AndAlso searchname <> String.Empty Then
If Integer.TryParse(num, numero) Then
For iter As Integer = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(iter).ToString.StartsWith(searchname) AndAlso ListBox1.Items(iter).ToString.Contains(num) Then
ListBox1.SetSelected(iter, True)
MessageBox.Show("Name : " & ListBox1.SelectedItem.ToString)
Exit Sub
End If
Next
End If
ElseIf searchname <> String.Empty Then
For iter As Integer = 0 To ListBox1.Items.Count - 1
If prenom <> String.Empty Then
If ListBox1.Items(iter).ToString.StartsWith(searchname) Then
ListBox1.SetSelected(iter, True)
foundstr &= ListBox1.SelectedItem.ToString & Environment.NewLine
found = True
End If
Else
If ListBox1.Items(iter).ToString.Contains(searchname) Then
ListBox1.SetSelected(iter, True)
foundstr &= ListBox1.SelectedItem.ToString & Environment.NewLine
found = True
End If
End If

Next
End If

If found Then
MessageBox.Show("Name : " & Environment.NewLine & foundstr)
Else
MessageBox.Show("Aucun resultat", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If


End Sub

'pour chercher un groupe selon le prenom
 testlistbox("prenom")
'pour chercher selon un numero
testlistbox("prenom", ,"4")
'pour chercher selon le nom de famille
 testlistbox( , "familyname")
0
rsx602 Messages postés 140 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 28 août 2014
27 févr. 2014 à 14:36
Je veut pouvoir etre en mesure de chercher par les 3. Donc que sa sois par nom / prénom / numero je veut pouvoir sortir l'info de mes listbox dans un msgbox
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
Modifié par cs_ShayW le 27/02/2014 à 14:51
As tu testé le code ?
Quelle est la liste que tu as dans ta listbox ?
0
rsx602 Messages postés 140 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 28 août 2014
Modifié par rsx602 le 27/02/2014 à 15:45
Ma listbox1 contient les Prénom + Nom et la 2ieme listbox contient les extension (donc les numero). En general je vais surtout me servire du Nom ou prénom pour avoir l'extension de la personne. Voila pourquoi si il y a également plus d'un alexandre je dois pouvoir voir les 3 alexandre + les extension dans le msgbox. Ainsi vu que les Noms et Prénoms son dans le meme listbox je dois pouvoir trouvé la personne + son extension meme si je cherche par nom de famille. Example dans la screenshot plus haut que j'ai posté on peut voir que la listbox contient le nom + prénom donc si je cherche "Doyon" il dois pouvoir le trouvé dans le listbox et sortir l'extension.
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
27 févr. 2014 à 16:01
Tiens encore du nouveau

Ton message initial parlait d'une listbox pas de deux
et ce que tu décris ici n'est pas ce que tu demandais au début
je te laisse
0
Rejoignez-nous