|
-
November 7th, 2019, 05:58 AM
#1
[RESOLVED] Finding an item (text) in a List View with Visual Studio 2012 Express
I am using Visual Studio 2012 Express
I have a List View that gets populated with words and their length (column 1) based upon a selection of a combo box - this works fine.
I have a button (code below) that attempts to search for a word in the list view and it is NOT working.
I want to find either the whole word or part of.
An example: I have a list of 50 bible words that populate the list view, I can successfully add a word using another button, so I add a name "sally" (just to test). "sally" gets added to the end of the list (preferred). Now I click on my search button and enter "sally" in the Input Box. When it searches, it highlights the first thing that "might" be sally:
("sa", "al", "all", "ly") and never "sally"!
I have literally searched the web looking and trying about 30 different ways to code this and NONE give me what I want.
May I please get some help with this?
Code:
' ********** THIS IS THE SEARCH BUTTON **********
' Step 1: Establish the variables I will use here in this subroutine.
Dim tmpInt1 As Integer = 0
Dim tmpString1 As String = Nothing
Dim tmpItem As ListViewItem = Nothing
' Step 2: Prompt the user for the word or characters to search for.
retry: tmpString1 = Trim(LCase(InputBox("Enter the word [or part of] to search for:", "Word Search")))
If tmpString1 Is Nothing Then Exit Sub
' Step 3: Determine if there is any illegal characters in the word being search for [!@#$%^&*()_-+=:'",<.>/?|\~`].
For x As Integer = 1 To Len(Trim(tmpString1))
If Mid(tmpString1, x, 1) < Chr(97) Or Mid(tmpString1, x, 1) > Chr(122) Then
MsgBox("You have entered an illegal character into the search box." & Chr(10) & "Re-enter the word you are searching for and click OK.")
GoTo retry
End If
Next
' Step 4: Search for the entered text in the list. If NOT found, inform the user and exit the subroutine.
tmpItem = ListView1.FindItemWithText(tmpString1, True, 0, True)
If Not tmpItem Is Nothing Then
ListView1.Focus()
ListView1.TopItem = tmpItem
tmpInt1 = ListView1.TopItem.Index
ListView1.Items(tmpInt1).Selected = True
Exit Sub
End If
MsgBox("The word or characters you searched for are NOT found in the list.")
Tags for this Thread
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
|