Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading and selecting items in a list box
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 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.
Can be used LB_x functions or accessible object functions. Example with LB_x functions:

Copy      Help
int hwnd=child("" "" win("Form1" "") 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:
Copy      Help
Acc a=acc("" "LIST" win("Form1" "") "" "" 0x1000)
for a.elem 1 10000000
,str s=a.Name; err break
,out s
Fantastic! I've decided to use the accessible object version, and


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

Thank you!
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:

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

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:

Copy      Help
Acc a=acc("listname" "LIST" windowname "" "" 0x1000)
Acc wholebox=a
for a.elem 1 20
,str thiselem=a.Name; err break
,if Need_To_Select(thiselem)
,,SendMessage item 0x00001013 i 0

Am I using this SendMessage wrong, or do I need an entirely different command? I apologize for the followup question... thanks in advance.
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.
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)