Posts: 272
Threads: 21
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: Jun 2012
Reputation:
0
hello,
i am trying to find indexes of items from a string.
i introduce a string in a textbox and click on a search button which has this function:
listBox1.FindString(textBox1.Text)
but with this, i only get first index.
how could i do to get all indexes?
i have tried
int[] idxs = listBox1.FindString(textBox1.Text)
but idxs is array type and listBox1.FindString(textBox1.Text) is int type, so i get an error.
could anyone help me please?
thanks in advance.
Posts: 207
Threads: 29
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: Jun 2011
Reputation:
0
i usually use this (vb.net)
Dim searchString As String = TextBox4.Text
Dim index As Integer = UserList.FindString(searchString)
If string.contains = true then, else error.
If index <> -1 Then
UserList.SetSelected(index, True)
Else
MsgBox("Not Found")
End If
may be in c# can be like :
string searchString = TextBox4.Text;
int index = UserList.FindString(searchString);
// If string.contains = true then, else error.
if (index != -1) {
UserList.SetSelected(index, true);
} else {
Interaction.MsgBox("Not Found");
}
Posts: 272
Threads: 21
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: Jun 2012
Reputation:
0
the problem of this is i only get one index and i want to get all indexes that contains char i have introduced in textbox
Posts: 768
Threads: 40
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: May 2011
Reputation:
0
I usually keep all listbox item in a List and when i search for something in the list u can loop trough that list and add everything that matches to the listbox