Determine highlighted (not selected) row (listindex) in a listbox or contents (1 Viewer)

cyberman55

Registered User.
Local time
Yesterday, 22:39
Joined
Sep 22, 2012
Messages
83
Ok, I thought I was a pretty good coder, but this one has me stumped and wondering if anyone can help with an obscure/arcane thing.

I have a listbox on a form. When I select an item in the list, I understand how to retrieve anything needed. But I found that if I select and item, and then hold down the left mouse button whilst moving up or down in the listbox each row is highlighted, but not actually selected until I release the mouse button.

The question is, is it possible to determine anything about the currently highlighted row before releasing the mouse button?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:39
Joined
Oct 29, 2018
Messages
21,477
Hi,

Just a thought but have you tried any of the mouse events?
 

cyberman55

Registered User.
Local time
Yesterday, 22:39
Joined
Sep 22, 2012
Messages
83
Yes, with the mousemove event I can read the values and listindex of first selection, but I can't figure out how to read anything about the highlighted rows as the cursor moves up or down in the list. It's weird since the highlighted row changes and you'd think there would be some property of the list to grab the index number of the highlighted rows. It's not the .selected property, as far as I can tell since that refers to the initial selection and doesn't change until the mouse button is release whilst the cursor is over a row in the list.

My guess is they never imagined it would be needed. But I'm working on an inspection application meant to work on iPhones and Androids via RDP clients. I've managed to get it to work by renting a server from apps4rent.com and running my database (2013) in the runtime. It's pretty cool since it opens the door to some clients who've rejected me by requiring a hosted solution. They told me accounts use it all the time. Their clients can access accounting software and the account can get to the data remotely.

Here's a demo I posted to my distributors showing the technology in action. http://www.screencast.com/t/uUUVqklc3JB If you're interested. I had to development touch-screen substitutes for simple things such as scrollbars since they're uselessly microscopic on a phone. I've seen a lot of posts about the issue, where developers grumble that MS doesn't let us make scrollbars wider.

Anyway, I suspect that the Access development team never anticipated the need to access the underlying info about a highlighted row. But, you never know, maybe they did and somebody here knows how to get to it.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 03:39
Joined
Feb 19, 2013
Messages
16,618
sounds like you have set your listbox multi select property to extended to achieve the effect you are getting.

In which case you can use code to loop through the itemselected collection. Something like

Code:
Dim itm
For Each itm In myListBox.ItemsSelected
    Debug.Print myListBox.ItemData(itm)
Next itm

the item you would want would (I think) be the first or last, depending on which way the mouse is going
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:39
Joined
Oct 29, 2018
Messages
21,477
Hi Claude,


So while using the mousemove event, are you able to use any of the other potential properties like SelTop and SelLength?


Just curious...
 

cyberman55

Registered User.
Local time
Yesterday, 22:39
Joined
Sep 22, 2012
Messages
83
Thanks CJ, but it's not multi-select and all I get is the selected first item (in the mousemove event). To get the highlighting effect, I have to click on one of the items. Then, while holding down the mouse button and moving up and down over the list I see different rows highlighted which serve to show which row will be selected when the mouse button is released. I want to find out what row is highlighted before releasing the mouse button. It's a tough one. I don't want to introduce multi-select into the mix since I have a ton of code to move in the list via slider-bar simulating labels, search functions, etc.
 

cyberman55

Registered User.
Local time
Yesterday, 22:39
Joined
Sep 22, 2012
Messages
83
Hi DBGUY, I don't see intellisense options for those properties in the listbox. I think they may be applicable to textboxes.
 

isladogs

MVP / VIP
Local time
Today, 03:39
Joined
Jan 14, 2017
Messages
18,239
Hi
I hate to spoil the party but I don't believe you can do what you want with a simple listbox. Whether it's possible with multiselect I'm unsure.
 

cyberman55

Registered User.
Local time
Yesterday, 22:39
Joined
Sep 22, 2012
Messages
83
Thanks isadogs, it's not that big a deal to me if the functionality doesn't exist. It would be nice if the highlighted row could be accessed, for me it's the row number I want, but I could see perhaps using it to get more detail about the item and then popping up an informational form (I can't use tooltips since they are too small to see on a phone). Going to tiny phone screens requires a lot of work-arounds.
 

cyberman55

Registered User.
Local time
Yesterday, 22:39
Joined
Sep 22, 2012
Messages
83
Thanks, that's some nice piece of coding. I thought about reading the mouse coordinates to grab info. I'm doing that now with the slider-imitation-control labels (based on some else's work). But, I can't find a way to read anything unless a selection is made, such as by using the arrow keys while in the listbox. I want to just know what row is highlighted so I can scrape the listindex number or something, anything...

There are other things I would love to know, although I didn't mention in my original posting. For example, if one drops the cursor below the list box, it automatically starts scrolling. That's a potentially useful characteristic in the mobile space, but I'd like to get a handle (no pun intended) on that too, for example to slow it down or control the rate of movement. It would be nice to have the rate of scrolling dependent on the distance from the listbox. It's not, its fixed. If an event were exposed, I could certainly slow it down with pause code.

The problem is that these functions are not needed in the normal desktop environment. That's why developers are moving to other platforms, particularly for the mobile space.

I'm sure it could be done. But who has weeks to develop it?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 03:39
Joined
Feb 19, 2013
Messages
16,618
there is a lot that can be done with the mouse move events, I have a number of functions that mimic the touch screen experience for when my apps are run on a tablet or smartphone, although there are a few that cannot be replicated.

you might find this link of interest. You will see that many provide the same parameters as used in the mouse events

https://docs.microsoft.com/en-us/windows/desktop/wintouch/windows-touch-portal

However I do not see the behaviour you describe so not really clear what you are trying to achieve. I use 2010, so perhaps there has been a change to the way things work in later versions
 

Users who are viewing this thread

Top Bottom