473,770 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Listview set cursor position for arrows

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_TextChan ged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles txtLoc.TextChan ged
Dim boolFound As Boolean
Dim i As Integer
Dim intLen As Integer
Dim Item As ListViewItem
Dim strLoc As String

strLoc = txtLoc.Text.Tri m ' 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.Subst ring(0,intLen)
= strLoc Then
lvw.Items(i).Se lected = True
lvw.Items(i).En sureVisible()
boolFound = True
Else
lvw.Items(i).Se lected = False
End If
Catch ex As Exception
lvw.Items(i).Se lected = False
End Try
Next
End Sub

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

Thanks

PS. This is a resubmission. I didn't get an answer three months ago.
Nov 20 '05 #1
4 4961
hmm...
Shane,

Where is your keydown code ?

Appears that you should set SelectedIndex+= 1 for that or -=1 in other
direction

Otherwise something is resetting the listview (making it refresh, losing
current position--becomes 0) and then pressing is thus item (1) which is the
2nd element.

What do you think?

Please show me the keydown code.
I like your name,

Shane
"Shane" <sh***********@ yahoo.com> wrote in message
news:4b******** *************** **@posting.goog le.com...
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_TextChan ged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles txtLoc.TextChan ged
Dim boolFound As Boolean
Dim i As Integer
Dim intLen As Integer
Dim Item As ListViewItem
Dim strLoc As String

strLoc = txtLoc.Text.Tri m ' 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.Subst ring(0,intLen)
= strLoc Then
lvw.Items(i).Se lected = True
lvw.Items(i).En sureVisible()
boolFound = True
Else
lvw.Items(i).Se lected = False
End If
Catch ex As Exception
lvw.Items(i).Se lected = False
End Try
Next
End Sub

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

Thanks

PS. This is a resubmission. I didn't get an answer three months ago.

Nov 20 '05 #2
I don't have any keydown code. If you click on an entry with the
mouse, the arrow keys work correctly. I can't find an equivalent of a
"SelectedIn dex" property that I can manually set in the code that
Microsoft obviously sets on a mouse click.

I could probably kludge together a solution. The original code that I
posted will highlight the appropriate entry in the listview box. I
could save the index of the matching entry; there is at most one. Call
another routine that uses "SendKeys.S end" with {Home} to start at the
top then sends a "{Down}" multiple times until I find a match.

I would HATE to do the kludge, when I know that there has to be a
property that I can set or a method that I can call.

Shane
Nov 20 '05 #3
I found the answer on my own. I'm posting the answer in case any other
poor slob runs into this problem.

lvw.Items(i).Fo cused = True
Nov 20 '05 #4
Appears to me that you are never telling the listview to move down. You are
just setting it to have focus....

Am I missing something?

If you trap a keyup in textbox and want that to occur in the listview then
you must somehow tell it to move down once...

I tried this...
Private Sub TextBox1_KeyDow n(ByVal sender As Object, ByVal e As
System.Windows. Forms.KeyEventA rgs) Handles TextBox1.KeyDow n
If e.KeyCode = Keys.Down Then
'assuming no multiselect
For i As Integer = 0 To ListView1.Items .Count - 1
If ListView1.Items (i).Selected AndAlso i <>
ListView1.Items .Count - 1 Then
ListView1.Items (i).Selected = False
ListView1.Items (i + 1).Selected = True
ListView1.Focus ()
e.Handled = True
Exit For
End If
Next
ElseIf e.KeyCode = Keys.Up Then
'do similar to above

End If
End Sub

it selects items and moves down when you click down arrow while in text
box--also switching focus to the listview. Is that what you wanted?

I see what you are talking about... there isn't a selectedindex property for
ListView.

Apparently you have to iterate it.

Sorry I couldn't help you more.

Shane
"Shane" <sh***********@ yahoo.com> wrote in message
news:4b******** *************** ***@posting.goo gle.com...
I don't have any keydown code. If you click on an entry with the
mouse, the arrow keys work correctly. I can't find an equivalent of a
"SelectedIn dex" property that I can manually set in the code that
Microsoft obviously sets on a mouse click.

I could probably kludge together a solution. The original code that I
posted will highlight the appropriate entry in the listview box. I
could save the index of the matching entry; there is at most one. Call
another routine that uses "SendKeys.S end" with {Home} to start at the
top then sends a "{Down}" multiple times until I find a match.

I would HATE to do the kludge, when I know that there has to be a
property that I can set or a method that I can call.

Shane

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2334
by: Richard | last post by:
Hi. I use a ListView to display data in tabular form. Each ListView row corresponds to a data record. The ListView Item of the record is the record key or code. Each SubItem in that row represents a field from the record. I implemented a context menu so the user can "Copy" the cell content to the clipboard with this code:
10
2889
by: Bill H | last post by:
I used a bit of JS on a page that is fairly long and didn't like the way that <A HREF='#' ONCLICK=\"... refreshed the page to the top. Removing the HREF (<A ONCLICK=\"...) solved my "problem" however the cursor no longer changes into the little hand when rolling over the link. Can I have both? No HREF and the little hand?
2
19283
by: Peter Steele | last post by:
I have a form containing a ListView with four columns, creating a multi-cell table. I want to have an event which can determine which cell in the table is under the cursor when a double-click is done. The double-click event of the ListView double-click event handler only passes in the sender object and the EventArgs object. How can I figure out the specific cell where the click occurred? Peter Steele CIENA Corp.
2
11660
by: Michael C | last post by:
Hi all, When I try to use the GetItemAt (e.X, e.Y) method in a ListView MouseDown() event, it only works some of the time. If I right-click on an open area of the ListView, I get null back as expected. If I right-click on a ListViewItem, I get that ListViewItem back. But then... if I right-click on an open area of the ListView again I get the last ListViewItem I clicked on back... I'm sure there's a way around this. GetItemAt...
0
4498
by: cyrille | last post by:
Hello from example from web i did a little code to avoiding columnHeader resize. this code seems to work well, but when I put a 'normal' ListView on the same Form than my overrided ListView it seems to stop working. if I'm resizing 'normal' ListView ColumnHeaders, then I can resizing ColumnHeaders of my overrided ListView. If I don't resizing 'normal' ListView ColumnHeaders, then resizing of my overrided ListView ColumnHeaders is...
1
1895
by: jrhoads23 | last post by:
Hello, I subclassed my own ListView which supports column sorting. It automatically draws the up/down sort arrows in the column header. The arrows that are used are drawn by me. I noticed that Windows XP systems uses different sort arrows than Windows 2000 and earlier systems. (open Windows Explorer and check them out on the two differnt O/S) I would like my ListView to use the same arrows as the operating system uses. Is there an API...
5
1385
by: Matt Michael | last post by:
Hi, I'm having a problem working with a listview in an application I'm writing. Currently, whenever the selectedindex changed event fires, it loads up a htmledit control, and other labels on the form, with the current information associated with the listview item. Whenever I click on each item, it works fine, but it seems that whenever I use the up/down arrows(important) to scroll through the list, it loses focus, and goes to the...
2
2936
by: Matt Michael | last post by:
Hi, I'm having a problem working with a listview in an application I'm writing. Currently, whenever the selectedindex changed event fires, it loads up a htmledit control, and other labels on the form, with the current information associated with the listview item. The control is called HtmlEdit and it references Microsoft.Mshtml Whenever I click on each item, it works fine, but it seems that whenever I use the up/down arrows(important)...
1
5375
by: Sim | last post by:
Hello NG, I try to use drag and drop function between two list views. For this I found following code: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchimpdragdrop.asp It works fine, but I have another problem. I want to create functionality like a Windows Explorer. This means, if I select some items from list view No 1 and drag&drop this to the list view No 2, then I want to mark automatically
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.