Page 1 of 1

Listview search

Posted: Tue Dec 18, 2012 10:46 pm
by AnoPem
How can i search in a listview where it dosent matter if the char is upper or lower case?

Re: Listview search

Posted: Tue Dec 18, 2012 11:07 pm
by Dummy1912
hi
there are lots of stuff to find :)
so tell us what kind of data are you wanted to search for?

Re: Listview search

Posted: Tue Dec 18, 2012 11:19 pm
by AnoPem
Dummy1912 wrote:
hi
there are lots of stuff to find :)
so tell us what kind of data are you wanted to search for?
I 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

Re: Listview search

Posted: Tue Dec 18, 2012 11:25 pm
by Dummy1912
what about this?
Code: Select all
    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

Re: Listview search

Posted: Tue Dec 18, 2012 11:27 pm
by AnoPem
Dummy1912 wrote:
what about this?
Code: Select all
    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

How would i use this dunnno;

Re: Listview search

Posted: Tue Dec 18, 2012 11:28 pm
by Dummy1912
just copy this code
just add a searchbox --> textbox
type something and press return key

replace lvUser with your listview