Listview search
Posted: Tue Dec 18, 2012 10:46 pm
How can i search in a listview where it dosent matter if the char is upper or lower case?
Sharing, Teaching and Supporting coders of all ages and levels since 2009
https://www.codenstuff.com/forum/
Dummy1912 wrote:hiI have a listview where i there has been loaded movies like RED but i want the user to be able to just search red and it will find it instead of having to search RED with upper case
there are lots of stuff to find
so tell us what kind of data are you wanted to search for?
Private Sub searchBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles searchBox.KeyPress
If Asc(e.KeyChar) = 13 Then
Dim itm As ListViewItem
Dim i As Integer
For i = 0 To lvUser.Items.Count - 1
lvUser.Items(i).Selected = False
lvUser.Items(i).BackColor = Color.White
Next
With lvUser
itm = .FindItemWithText(searchBox.Text, False, 0, True)
If Not itm Is Nothing Then
'.TopItem = itm
.Items.Item(itm.Index).BackColor = Color.BurlyWood
.Items.Item(itm.Index).EnsureVisible()
Else
MsgBox("No Record Found!")
For i = 0 To lvUser.Items.Count - 1
lvUser.Items(i).Selected = False
lvUser.Items(i).BackColor = Color.White
Next
.Items(0).EnsureVisible()
.Items.Item(0).BackColor = Color.BurlyWood
searchBox.SelectionStart = 0
searchBox.SelectionLength = Len(searchBox.Text)
searchBox.Focus()
End If
End With
itm = Nothing
End If
End Sub
Dummy1912 wrote:what about this?
Code: Select allPrivate Sub searchBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles searchBox.KeyPress If Asc(e.KeyChar) = 13 Then Dim itm As ListViewItem Dim i As Integer For i = 0 To lvUser.Items.Count - 1 lvUser.Items(i).Selected = False lvUser.Items(i).BackColor = Color.White Next With lvUser itm = .FindItemWithText(searchBox.Text, False, 0, True) If Not itm Is Nothing Then '.TopItem = itm .Items.Item(itm.Index).BackColor = Color.BurlyWood .Items.Item(itm.Index).EnsureVisible() Else MsgBox("No Record Found!") For i = 0 To lvUser.Items.Count - 1 lvUser.Items(i).Selected = False lvUser.Items(i).BackColor = Color.White Next .Items(0).EnsureVisible() .Items.Item(0).BackColor = Color.BurlyWood searchBox.SelectionStart = 0 searchBox.SelectionLength = Len(searchBox.Text) searchBox.Focus() End If End With itm = Nothing End If End Sub