Selecting Items in ListView control ?

Class library usage, coding and language questions.
Posts: 15
Joined: Wed May 23, 2007 11:12 pm

Selecting Items in ListView control ?

Post by vonBrabant » Thu May 24, 2007 10:50 pm


I'm just getting started with Ranorex and I have a problem with a ListView control whose items have no name.

I can get the number of items with ListViewGetItemCount(), but how can I select an item if it has no name? ListViewSelectItem() wants a name and not an item number :-(


Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by webops » Thu May 24, 2007 11:24 pm

You can use the Element functions, the element approach supports a general way for automating components, the following code dumps out and selects all elements of the list view in the VS2005Application:

Code: Select all

print '--------------------------------------------------------------------'
print ' Searching and testing the list view'
print '---------------------------------------------------------------------'
print '   searching the list view by control name'
if listView == 0:
    print 'ERROR: listView not found'
    return 1        

print '      listView=' + hex(listView)

print '      moving the mouse to the control'
element = Ranorex.ControlGetElement(listView)
if element == 0:
    print 'ERROR: listView element not found'
    return 1        

listElement = Ranorex.ElementFindChild(element, Ranorex.ROLE_SYSTEM_LIST)
if listElement == 0:
    print 'ERROR: list element not found'
    return 1        
# Dump out all list items
childCount = Ranorex.ElementGetChildCount(listElement);
for index in range(0,childCount):
    item = Ranorex.ElementGetChild(listElement,index)
    if item == None:
    print '      Item = ' + Ranorex.ElementGetName(item)
    Ranorex.ElementSelect(item, Ranorex.SELFLAG_TAKEFOCUS | Ranorex.SELFLAG_TAKESELECTION);
Ranorex Team