Hi,
sorry if this is trivial, but I can't find a way to get the index (or text) of the currently selected item of a list view control
I can select items with ListViewSelectItemIndex but there is no corresponding function for finding out which item is selected.
What am I overlooking ?
Getting selected item from ListView ??
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Unfortunately, this function is not available.
The following workaround can be used:
From your ListView, get the Element and walk through its children (which are of Role ListItem). The item which is currently selected has the state "selected", not selected items have the state "selectable"
Michael
Ranorex Team
The following workaround can be used:
From your ListView, get the Element and walk through its children (which are of Role ListItem). The item which is currently selected has the state "selected", not selected items have the state "selectable"
Michael
Ranorex Team
-
- Posts: 15
- Joined: Wed May 23, 2007 11:12 pm
Okay, that would be good enough, but it doesn't really work.
The problem is that STATE_SYSTEM_SELECTED evaluates to '2', while ElementGetState returns either 2097152 (2^21) if the item is not selected and 2097154 (2^21+2) if the item is selected !!
So, am I supposed to play around with bit masks for this comparison to work, or what am I doing wrong ?
Many thanks
The problem is that STATE_SYSTEM_SELECTED evaluates to '2', while ElementGetState returns either 2097152 (2^21) if the item is not selected and 2097154 (2^21+2) if the item is selected !!
So, am I supposed to play around with bit masks for this comparison to work, or what am I doing wrong ?
Many thanks
Code: Select all
element = Ranorex.ControlGetElement(listViewHwnd)
itemCount = Ranorex.ElementFindChildren(element,Ranorex.ROLE_SYSTEM_LISTITEM,
None,None,Ranorex.MATCH_EXACT)
for idx in range(itemCount):
childE = Ranorex.ElementGetChildFieldItem(idx)
bla = Ranorex.ElementGetState(childE) # for debugging
bli = Ranorex.STATE_SYSTEM_SELECTED # for debugging
if Ranorex.ElementGetState(childE)==Ranorex.STATE_SYSTEM_SELECTED:
break
# for
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact: