Getting selected item from ListView ?? : Automation API

Getting selected item from ListView ??

Class library usage, coding and language questions.

Getting selected item from ListView ??

Postby vonBrabant » Thu May 22, 2008 10:52 pm

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 ?
vonBrabant
 
Posts: 15
Joined: Thu May 24, 2007 12:12 am

Postby Support Team » Fri May 23, 2008 11:21 am

Unfortunately, this function is not available. :oops:

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
User avatar
Support Team
Site Admin
 
Posts: 4289
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Postby vonBrabant » Fri May 23, 2008 1:19 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



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
vonBrabant
 
Posts: 15
Joined: Thu May 24, 2007 12:12 am

Postby Support Team » Fri May 23, 2008 2:03 pm

Just use

Ranorex.ElementGetState(childE) & Ranorex.STATE_SYSTEM_SELECTED
instead of
Ranorex.ElementGetState(childE)==Ranorex.STATE_SYSTEM_SELECTED
User avatar
Support Team
Site Admin
 
Posts: 4289
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Postby vonBrabant » Fri May 23, 2008 6:26 pm

yeah, you are right.
Everything is find ;-)
vonBrabant
 
Posts: 15
Joined: Thu May 24, 2007 12:12 am


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests