By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,002 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,002 IT Pros & Developers. It's quick & easy.

Listview select from Textbox string

P: n/a
I have a text box select items in a listview as text is being typed
into the text box. I get the select bar to move correctly in the
Listview control.

If the user presses the down or up key in the text box, I want to move
to the selected item in the listview box.

The down or up arrow does set focus to the listview box and the
selected item switches from the grey of being unfocused to the blue of
focus. So far, so good.

Pressing the down arrow again moves to the second entry in the
listview instead of the entry below the currently highlighted entry.
Susbsequent cursor movements work.

Obviously, the selected table index that I'm using is not working
correctly. What do I need to do to fix it?

Private Sub txtLoc_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles txtLoc.TextChanged
Dim boolFound As Boolean
Dim i As Integer
Dim intLen As Integer
Dim Item As ListViewItem
Dim strLoc As String

strLoc = txtLoc.Text.Trim ' Get the string
If strLoc = "" Or strLoc = Nothing Then Exit Sub
intLen = strLoc.Length ' Length of substring

For i = 0 To lvw.Items.Count - 1
Item = lvw.Items(i) ' Get the item
Try
If boolFound = False And Item.Text.Substring(0,
intLen) = strLoc Then
lvw.Items(i).Selected = True
lvw.Items(i).EnsureVisible()
boolFound = True
Else
lvw.Items(i).Selected = False
End If
Catch ex As Exception
lvw.Items(i).Selected = False
End Try
Next
End Sub

Private Sub txtLoc_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtLoc.KeyUp
If e.KeyData = Keys.Down Then lvw.Focus()
If e.KeyData = Keys.Up Then lvw.Focus()
End Sub

Thanks
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
sorry
do you know how to print images which inside listview control??

"Shane" <sh***********@yahoo.com> wrote in message
news:4b**************************@posting.google.c om...
I have a text box select items in a listview as text is being typed
into the text box. I get the select bar to move correctly in the
Listview control.

If the user presses the down or up key in the text box, I want to move
to the selected item in the listview box.

The down or up arrow does set focus to the listview box and the
selected item switches from the grey of being unfocused to the blue of
focus. So far, so good.

Pressing the down arrow again moves to the second entry in the
listview instead of the entry below the currently highlighted entry.
Susbsequent cursor movements work.

Obviously, the selected table index that I'm using is not working
correctly. What do I need to do to fix it?

Private Sub txtLoc_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles txtLoc.TextChanged
Dim boolFound As Boolean
Dim i As Integer
Dim intLen As Integer
Dim Item As ListViewItem
Dim strLoc As String

strLoc = txtLoc.Text.Trim ' Get the string
If strLoc = "" Or strLoc = Nothing Then Exit Sub
intLen = strLoc.Length ' Length of substring

For i = 0 To lvw.Items.Count - 1
Item = lvw.Items(i) ' Get the item
Try
If boolFound = False And Item.Text.Substring(0,
intLen) = strLoc Then
lvw.Items(i).Selected = True
lvw.Items(i).EnsureVisible()
boolFound = True
Else
lvw.Items(i).Selected = False
End If
Catch ex As Exception
lvw.Items(i).Selected = False
End Try
Next
End Sub

Private Sub txtLoc_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtLoc.KeyUp
If e.KeyData = Keys.Down Then lvw.Focus()
If e.KeyData = Keys.Up Then lvw.Focus()
End Sub

Thanks

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.