Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading and selecting items in a list box
#1
I've found various other threads on handling list boxes, but it looks like most of the responses presume some knowledge that I don't have. I apologize for the basic level of this question, but I'm really stuck...

I'm running an application that makes a list box, whose class is +WindowsForms10.LISTBOX.app.0.378734a. Sometimes all of the list's elements are visible, and sometimes there's a scroll bar so that you can't see all of them until you scroll.

I have written QM code that gets the handle of the list box. Now I need to (1) read the text in every individual element of the list, and then (2) select some of the elements of the list.

I can't figure out how to do either of these things. I have tried using the "Control-Specific Actions" dialog box to select one of the list box items by its index, but even that doesn't seem to work. I don't get an error message, but nothing appears to happen, either. And even if that did work, I'd still have the problem of how to read the elements in, in the first place.

Any help would be greatly appreciated.
#2
Can be used LB_x functions or accessible object functions. Example with LB_x functions:

Code:
Copy      Help
int hwnd=child("" "WindowsForms10.LISTBOX.app.0.378734a" win("Form1" "WindowsForms10.Window.8.app.0.378734a") 0x1)
int i
str s
for i 0 LB_GetCount(hwnd)
,LB_GetItemText(hwnd i s)
,out s

LB_SelectItem hwnd 2

Example with accessible object functions:
Code:
Copy      Help
Acc a=acc("" "LIST" win("Form1" "WindowsForms10.Window.8.app.0.378734a") "WindowsForms10.LISTBOX.app.0.378734a" "" 0x1000)
for a.elem 1 10000000
,str s=a.Name; err break
,out s
#3
Fantastic! I've decided to use the accessible object version, and

a.Select(SEFLAG_ADDSELECTION)

is working perfectly to select the list items that I need.

Thank you!
#4
Oops, one last problem. It turns out that I can't just use a.Select(SELFLAG_ADDSELECTION) to select each list item, because there's another part of this application that needs to detect the actual click of the mouse on the list item, in order to enable something else.

Usually that's no problem, because I can just click on the list item, like this:

Code:
Copy      Help
Acc a=acc("listname" "LIST" windowname "WindowsForms10.LISTBOX.app.0.378734a" "" 0x1000)
for a.elem 1 20
,str thiselem=a.Name; err break
,if Need_To_Select(thiselem)
,,a.Mouse(1)

But sometimes the list is too long to fit in its list box, so a scroll bar appears. Then, when I try to click on a desired list item that's not visible (because I would need to scroll down to it) I get an error message.

I found LVM_ENSUREVISIBLE, but I'm not sure it works with this type of list box. This doesn't seem to help at all:

Code:
Copy      Help
Acc a=acc("listname" "LIST" windowname "WindowsForms10.LISTBOX.app.0.378734a" "" 0x1000)
Acc wholebox=a
for a.elem 1 20
,str thiselem=a.Name; err break
,if Need_To_Select(thiselem)
,,item=child(wholebox)
,,SendMessage item 0x00001013 i 0
,,probe.Mouse(1)
,,a.Mouse(1)

Am I using this SendMessage wrong, or do I need an entirely different command? I apologize for the followup question... thanks in advance.
#5
Try DoDefaultAction instead of select (it should do "Double Click"). Or LB_Select (item index is a.elem-1).

If it needs real mouse click, to scroll into view try SELFLAG_TAKEFOCUS|SELFLAG_TAKESELECTION instead of SELFLAG_ADDSELECTION. I think it should scroll automatically. Or send LB_SETTOPINDEX message. Don't use LVM_ messages as they are for list view controls.
#6
Well, DoDefaultAction didn't seem to do anything. Neither did LB_Select. I didn't want to try SELFLAG_TAKEFOCUS|SELFLAG_TAKESELECTION because I needed to allow multiple list items to be selected at once, and I didn't want to de-select the others. But I think LB_SETTOPINDEX is working so far. That's a very handy message.


Forum Jump:


Users browsing this thread: 1 Guest(s)