Search in listview ( vb.com )
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
6 posts
Page 1 of 1
idk if thats search or find, but i want a user to type in a textbox something then he press Search it will highlight the item/items (if possible) that is the same as textbox
IF possible to even check the WHOLE sub items, not just the first, cuz this has 4 coloums in total so if thats possible please tell, my current code doesn't even highlight idk if it does scroll a bit but doesnt make the real find function
IF possible to even check the WHOLE sub items, not just the first, cuz this has 4 coloums in total so if thats possible please tell, my current code doesn't even highlight idk if it does scroll a bit but doesnt make the real find function
Code: Select all
Dim foundItem As ListViewItem = _
ListView1.FindItemWithText(txtFind.Text, False, 0, True)
If (foundItem IsNot Nothing) Then
ListView1.TopItem = foundItem
End If
I don't remember where this code came from but I used this in my Animal Crossing program to search for items in a Listbox.
Code for the search button:
Goodluck!
Code: Select all
Then you need to add this code below to the button that will search for the term the user inputs. Public Sub SearchCharacters(ByVal searchTerm As String)
Try
For Each lbItem As Object In lstCharacters.Items
If lbItem.ToString = searchTerm Then
lstCharacters.SelectedItem = lbItem
End If
Next
Catch ex As Exception
End Try
End Sub
Code: Select all
Put that on the Textbox KeyDown event so the user doen't have to click the button, but can click Enter. If e.KeyCode = Keys.Enter Then
e.SuppressKeyPress = True
Dim s As String = txtSearchCharacter.Text
Dim s2 As String = StrConv(s, VbStrConv.ProperCase)
txtSearchCharacter.Text = s2
SearchCharacters(s2)
End If
Code for the search button:
Code: Select all
Searching for whaever term the user inputs is case sensitive, and the code will select the item it finds in the listbox, if nothing was found, nothing will be selected. Dim s As String = txtSearchCharacter.Text
Dim s2 As String = StrConv(s, VbStrConv.ProperCase)
txtSearchCharacter.Text = s2
SearchCharacters(s2)
Goodluck!

My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
You can use this code to search in listview sub items:
Code: Select all
The user just needs to click btnSearch after typing in the text. Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
ListView1.SelectedIndices.Clear()
ListView1.HideSelection = False
Dim found As List(Of Integer) = New List(Of Integer)
For row As Integer = 0 To ListView1.Items.Count - 1
For column As Integer = 0 To ListView1.Items(row).SubItems.Count - 1
If ListView1.Items(row).SubItems(column).Text.Contains(txtSearch.Text) Then
found.Add(row)
Exit For
End If
Next
Next
For i As Integer = 0 To found.Count - 1
ListView1.SelectedIndices.Add(found(i))
Next
End Sub
@smashapps, iknew about keydown and the enter thing but what does
@mandai, thanks for this code i will soon use it not now cuz i have fever cryer;
Code: Select all
mean e.SuppressKeyPress = True
@mandai, thanks for this code i will soon use it not now cuz i have fever cryer;
Gets or sets a value indicating whether the key event should be passed on to the underlying control.I use that to prevent the annoying ding windows makes when you press keys on your form.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
smashapps wrote:lol niceGets or sets a value indicating whether the key event should be passed on to the underlying control.I use that to prevent the annoying ding windows makes when you press keys on your form.

6 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023