|
-
Apr 30th, 2011, 09:09 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Insensative Listbox search
I am trying to do a search function for a listbox and I have the search working but it is case-sensitive. How do you make it non?
Code:
For i As Integer = 0 To FrmMain.LstBxMovie.Items.Count - 1
If Not cancelled Then
If FrmMain.LstBxMovie.Items(i).ToString.Contains(sSearchString) Then
FrmMain.LstBxMovie.SelectedIndex = i
'MsgBox(FrmMain.tvwMain.SelectedNode)
response = MsgBox("click ok to continue search, or cancel to abort search", MsgBoxStyle.OkCancel Or MsgBoxStyle.DefaultButton1 Or MsgBoxStyle.Question)
If response = MsgBoxResult.Cancel Then cancelled = True
End If
End If
Next
-
Apr 30th, 2011, 09:21 AM
#2
Re: Insensative Listbox search
Hi,
If you use the ListBox.Findstring method then the search is not Case sensitive.
vb Code:
Private Sub FindMyString(ByVal searchString As String)
' Ensure we have a proper string to search for.
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)
Else
MessageBox.Show("The search string did not match any items in the ListBox")
End If
End If
End Sub
-
Apr 30th, 2011, 09:27 AM
#3
Thread Starter
Frenzied Member
Re: Insensative Listbox search
anyway to incorporate that into my search function? I want to search for one and continue from there, not just find all.
-
Apr 30th, 2011, 09:39 AM
#4
Thread Starter
Frenzied Member
Re: Insensative Listbox search
I think the best way is to do .ToLower on both strings.
-
Apr 30th, 2011, 10:01 AM
#5
Re: Insensative Listbox search
 Originally Posted by phpman
anyway to incorporate that into my search function? I want to search for one and continue from there, not just find all.
The attached VS2008 + project has a method extension that will search, prompt user to continue after each find.
Code:
<System.Runtime.CompilerServices.Extension()> _
Public Sub FindSearchString(ByVal sender As ListBox, ByVal searchString As String)
If String.IsNullOrEmpty(searchString) Then
Exit Sub
End If
searchString = searchString.ToUpper
Dim Items = (From Item In sender.Items.Cast(Of String)() Select Item.ToUpper).ToList
For Row As Integer = 0 To sender.Items.Count - 1
If Items(Row).Contains(searchString) Then
sender.SetSelected(Row, True)
If MsgBox("click ok to continue search, or cancel to abort search", MsgBoxStyle.YesNo) <> MsgBoxResult.Yes Then
Exit Sub
End If
End If
Next
End Sub
-
Apr 30th, 2011, 10:08 AM
#6
Thread Starter
Frenzied Member
Re: Insensative Listbox search
Thanks Kevin, that is what I did, used ToLower instead of ToUpper. but thanks for the idea.
-
Apr 30th, 2011, 10:26 AM
#7
Re: Insensative Listbox search
 Originally Posted by phpman
Thanks Kevin, that is what I did, used ToLower instead of ToUpper. but thanks for the idea.
Both do the same in regards to what you wanted. Good to hear all worked out for you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|