find listviewitems with keyboard entries
-
hello, i want code following scenario i've got a listview with many entries. when the user write "tom" (with the keyboard) the programm should find the first entry with tom and mark this entry. have somebaody an idear? greetings from germany - can u rate by the way my english preferences???
-
hello, i want code following scenario i've got a listview with many entries. when the user write "tom" (with the keyboard) the programm should find the first entry with tom and mark this entry. have somebaody an idear? greetings from germany - can u rate by the way my english preferences???
I have something similar handling keypress event of the control, a combobox in my case. Although not is a "beautiful" code, it works fine enough for my problem, find the first letter entry. I hope you can modify it for your owm problem solution: Private Sub ComboBoxMacge_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress Try Dim cb As ComboBox = CType(sender, ComboBox) Dim findString As String = String.Empty If (Not e.KeyChar.IsLetter(e.KeyChar, 0)) Then Exit Sub findString = Char.ToUpper(e.KeyChar) If cb.DropDownStyle <> ComboBoxStyle.DropDownList Then If cb.SelectedText <> cb.Text Then findString = cb.Text & Char.ToUpper(e.KeyChar) End If End If Dim IDX As Integer = -1 With cb Dim ELE As Integer = 0 Dim R As DataRow Dim DW As DataRow() = Nothing Try DW = CType(.DataSource, DataRow()) Catch Try DW = CType(.DataSource, DataTable).Select() Catch ex As Exception End Try End Try If DW Is Nothing Then Dim s As String For Each s In cb.Items ' Se distinguen los que tienen codigo o los que no: Dim idxGuion As Integer = s.IndexOfAny("-") Dim pos As Integer If idxGuion < 0 Then ' no hay guion pos = 0 Else pos = idxGuion + 2 End If If s.IndexOf(findString) = pos Then IDX = ELE Exit For End If ELE += 1 Next Else For Each R In DW ' Se distinguen los que tienen codigo o los que no: Dim idxGuion As Integer = R(cb.DisplayMember).IndexOfAny("-") Dim pos As Integer If idxGuion < 0 Then ' no hay guion pos = 0 Else pos = idxGuion + 2 End If
-
I have something similar handling keypress event of the control, a combobox in my case. Although not is a "beautiful" code, it works fine enough for my problem, find the first letter entry. I hope you can modify it for your owm problem solution: Private Sub ComboBoxMacge_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress Try Dim cb As ComboBox = CType(sender, ComboBox) Dim findString As String = String.Empty If (Not e.KeyChar.IsLetter(e.KeyChar, 0)) Then Exit Sub findString = Char.ToUpper(e.KeyChar) If cb.DropDownStyle <> ComboBoxStyle.DropDownList Then If cb.SelectedText <> cb.Text Then findString = cb.Text & Char.ToUpper(e.KeyChar) End If End If Dim IDX As Integer = -1 With cb Dim ELE As Integer = 0 Dim R As DataRow Dim DW As DataRow() = Nothing Try DW = CType(.DataSource, DataRow()) Catch Try DW = CType(.DataSource, DataTable).Select() Catch ex As Exception End Try End Try If DW Is Nothing Then Dim s As String For Each s In cb.Items ' Se distinguen los que tienen codigo o los que no: Dim idxGuion As Integer = s.IndexOfAny("-") Dim pos As Integer If idxGuion < 0 Then ' no hay guion pos = 0 Else pos = idxGuion + 2 End If If s.IndexOf(findString) = pos Then IDX = ELE Exit For End If ELE += 1 Next Else For Each R In DW ' Se distinguen los que tienen codigo o los que no: Dim idxGuion As Integer = R(cb.DisplayMember).IndexOfAny("-") Dim pos As Integer If idxGuion < 0 Then ' no hay guion pos = 0 Else pos = idxGuion + 2 End If