Select data in a list box using index

Bug reports.
Nik
Posts: 18
Joined: Fri Sep 29, 2006 1:35 am

Select data in a list box using index

Post by Nik » Fri Sep 29, 2006 1:42 am

Hi,
I am not able to use RxListBoxSetSelectedIndex(hListControl1, 1);
function.
Executing this line closes the application on test.

However, I am able to use RxListBoxGetItemCount function.

As I understand the behaviour of RxListBoxSetSelectedIndex function, this will highlight the text on the index I'll provide, right?

This is my code:
HWND hListControl = RxFormFindChildClassName(form, "ListBox",1);
int playcount = RxListBoxGetItemCount( hListControl ) ;
playcount = RxListBoxSetSelectedIndex(hListControl,3 );

Is there any step am missing?
-Nikhil

Nik
Posts: 18
Joined: Fri Sep 29, 2006 1:35 am

Re: Select data in a list box using index

Post by Nik » Fri Sep 29, 2006 10:55 pm

Nik wrote:Hi,
I am not able to use RxListBoxSetSelectedIndex(hListControl1, 1);
function.
Executing this line closes the application on test.

However, I am able to use RxListBoxGetItemCount function.

As I understand the behaviour of RxListBoxSetSelectedIndex function, this will highlight the text on the index I'll provide, right?

This is my code:
HWND hListControl = RxFormFindChildClassName(form, "ListBox",1);
int playcount = RxListBoxGetItemCount( hListControl ) ;
playcount = RxListBoxSetSelectedIndex(hListControl,3 );

I am on WinXP and using VC++ (6.0)

Is there any step am missing?
-Nikhil

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

Post by admin » Sat Sep 30, 2006 12:26 am

Nik wrote:I am on WinXP and using VC++ (6.0)
Thank you for this info, I could reproduce the error now with a VC 6.0 ListBox.
It's a bug in RanorexCore, I will fix it for the next version: 0.9.4.
But you can use the following code in C++:

Code: Select all

HWND hListControl = RxFormFindChildClassName(form, "ListBox",1); 
if ( hListControl == 0 )
{
	printf(" ERROR: ListBox not found\n");
	exit(1);
}

int itemCount = RxListBoxGetItemCount( hListControl ); 
// int selectedIndex = RxListBoxSetSelectedIndex(hListControl, 3); 
int ret = ::SendMessage(hListControl, LB_SETCURSEL, 3, 0);
Please contact me, if it doesn't work, i can send you another work around with Elements.

Jenö Herget
Ranorex Team

Nik
Posts: 18
Joined: Fri Sep 29, 2006 1:35 am

SendMessage not working on Listbox

Post by Nik » Sat Sep 30, 2006 1:38 am

hi,
It is still not working with SendMessage. But the good thing is the application is not getting closed.
Pls send me the workaround using elements.

I am also working with TreeView. I am not able to select a path or folder in a tree.
The command I am using is
RxTreeViewSelectItem(hTreeControl, "Sample");
// where sample is the name of the folder. Here also I have to use the elements??

I appreciate your help.
-Nikhil

admin wrote:
Nik wrote:I am on WinXP and using VC++ (6.0)
Thank you for this info, I could reproduce the error now with a VC 6.0 ListBox.
It's a bug in RanorexCore, I will fix it for the next version: 0.9.4.
But you can use the following code in C++:

Code: Select all

HWND hListControl = RxFormFindChildClassName(form, "ListBox",1); 
if ( hListControl == 0 )
{
	printf(" ERROR: ListBox not found\n");
	exit(1);
}

int itemCount = RxListBoxGetItemCount( hListControl ); 
// int selectedIndex = RxListBoxSetSelectedIndex(hListControl, 3); 
int ret = ::SendMessage(hListControl, LB_SETCURSEL, 3, 0);
Please contact me, if it doesn't work, i can send you another work around with Elements.

Jenö Herget
Ranorex Team

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

Post by admin » Sat Sep 30, 2006 3:08 pm

Are you sure, that you use the correct ListBox handle? Please check it with RanorexSpy.
It's a better way to Find a control with RxFormFindChildControlName (for .NET controls, if you have a ControlName in RanorexSpy) or RxFormFindChildControlId (for older controls without a control name).
A ControlName is a unique identifier in a .NET form and a ControlId is a unique identifies in older windows applications or dialogs.

Sample code for selecting list box items with elements:

Code: Select all

...
// Get the Element of the ListBox
ElementStruct element;
if ( RxControlGetElement(hListControl, &element) == FALSE)
{
    printf("    ERROR: ListBox GetElement\n");
    return 1;
}

// Find and select the list item with the name Item3
ElementStruct listItem;
BOOL bRet = RxElementFindChild(&element, ROLE_SYSTEM_LISTITEM, "Item3", NULL, &listItem);
if (bRet==TRUE)
{
    printf("    List item found\n");
    RxElementSelect(&listItem, SELFLAG_TAKEFOCUS | SELFLAG_TAKESELECTION);
    RxSleep(500);
}
// Dump out all list items
ElementStruct listElement;
if ( RxElementFindChild(&element, ROLE_SYSTEM_LIST, NULL, NULL, &listElement) == TRUE )
{
    int childCount = RxElementGetChildCount(&listElement);
    for(int i=0; i< childCount; i++)
    {
        if ( RxElementGetChild(&listElement, i, &listItem) == TRUE )
        {
            printf("    Item(%d)=%s\n",i,listItem.Name);
            RxElementSelect(&listItem, SELFLAG_TAKEFOCUS | SELFLAG_TAKESELECTION);
            RxSleep(300);
        }
    }
}
Sample code for selecting tree view items with elements:

Code: Select all

...
HWND hTreeView = RxFormFindChildControlName(form, "treeView1"); 
if ( hTreeView == 0 )
{
    printf(" ERROR: TreeView not found\n");
    return 1;
}

// Get the Element of the TreeView
ElementStruct element;
if ( RxControlGetElement(hTreeView, &element) == FALSE)
{
    printf("    ERROR: TreeView GetElement\n");
    return 1;
}

// Find and select the tree item with the name SecondNode 
ElementStruct treeItem;
bRet = RxElementFindChild(&element, ROLE_SYSTEM_OUTLINEITEM, "SecondNode", NULL, &treeItem);
if (bRet==TRUE)
{
    printf("    Tree item found\n");
    RxElementSelect(&treeItem, SELFLAG_TAKEFOCUS | SELFLAG_TAKESELECTION);
    RxSleep(1000);
}
// Dump out all tree items
ElementStruct treeElement;
if ( RxElementFindChild(&element, ROLE_SYSTEM_OUTLINE, NULL, NULL, &treeElement) == TRUE )
{
    int childCount = RxElementGetChildCount(&treeElement);
    for(int i=0; i< childCount; i++)
    {
        if ( RxElementGetChild(&treeElement, i, &treeItem) == TRUE )
        {
            printf("    Item(%d)=%s\n",i,treeItem.Name);
            RxElementSelect(&treeItem, SELFLAG_TAKEFOCUS | SELFLAG_TAKESELECTION);
            RxSleep(300);
        }
    }
}
I tested the samle code with VS2005Application.exe

Jenö Herget
Ranorex Team

Nik
Posts: 18
Joined: Fri Sep 29, 2006 1:35 am

Re: Select data in a list box using index

Post by Nik » Sun Oct 01, 2006 7:15 am

hi,
Listbox is now working for me. Thanks.
In the tree view, if i have to select embedded folder e.g. C:\folder1\folder2\folder3. Is there a direct command or I have to go be the element way?
Please advice.

I appreciate your quick responses.

-Nikhil

Nik wrote:Hi,
I am not able to use RxListBoxSetSelectedIndex(hListControl1, 1);
function.
Executing this line closes the application on test.

However, I am able to use RxListBoxGetItemCount function.

As I understand the behaviour of RxListBoxSetSelectedIndex function, this will highlight the text on the index I'll provide, right?

This is my code:
HWND hListControl = RxFormFindChildClassName(form, "ListBox",1);
int playcount = RxListBoxGetItemCount( hListControl ) ;
playcount = RxListBoxSetSelectedIndex(hListControl,3 );

Is there any step am missing?
-Nikhil

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

Post by admin » Sun Oct 01, 2006 10:11 am

Try the function RxTreeViewSelectPath(), it should work with VS 6.0, but we test Ranorex only with Visual Studio 2003 and Visual Studio 2005.

Code: Select all

/// <summary>
/// The function selects the specified tree-view path and
/// scrolls the item into view
/// The elements of the path will be separeted with "/".
/// Example of itemPath: "Rootname/SubItemName/SubSubItemName"
/// </summary>
/// <param name="hWnd">Handle to the treeview.</param>
/// <param name="itemPath">Item path.</param>
/// <returns>
/// If the function succeeds, the return value is zero, 
/// otherwise the return value is an error code. 
/// </returns>
RANOREXCORE_API int RxTreeViewSelectPath(HWND hWnd, char* itemPath);
Please use the Element functions, if you have a problem.

Jenö Herget
Ranorex Team

Nik
Posts: 18
Joined: Fri Sep 29, 2006 1:35 am

OS support

Post by Nik » Mon Oct 02, 2006 7:35 pm

Hi,
Just want to know if Ranorex APIs would work with Windows 98, ME and NT 4.x.

Thanks,
Nikhil
admin wrote:Try the function RxTreeViewSelectPath(), it should work with VS 6.0, but we test Ranorex only with Visual Studio 2003 and Visual Studio 2005.

Code: Select all

/// <summary>
/// The function selects the specified tree-view path and
/// scrolls the item into view
/// The elements of the path will be separeted with "/".
/// Example of itemPath: "Rootname/SubItemName/SubSubItemName"
/// </summary>
/// <param name="hWnd">Handle to the treeview.</param>
/// <param name="itemPath">Item path.</param>
/// <returns>
/// If the function succeeds, the return value is zero, 
/// otherwise the return value is an error code. 
/// </returns>
RANOREXCORE_API int RxTreeViewSelectPath(HWND hWnd, char* itemPath);
Please use the Element functions, if you have a problem.

Jenö Herget
Ranorex Team

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

Post by admin » Mon Oct 02, 2006 8:14 pm

Nikhil wrote:Just want to know if Ranorex APIs would work with Windows 98, ME and NT 4.x.
Ranorex should work with every Windows versions, but you must have MSAA 2.0 installed.

We test Ranorex only with Windows XP and Vista.
Please inform us about the results.

Jenö Herget
Ranorex Team

Stewie
Posts: 1
Joined: Sat Oct 07, 2006 11:17 am

TreeNavigation using Element functions

Post by Stewie » Sat Oct 07, 2006 11:49 am

1. The above provided solution to navigation works for navigating through top level nodes. The API RxElementFindChild fails to find children for a particular elemnt. Is this functionality tested?
2. The TreeView API work to navigate through children, but there is no mechanism to perfom actions on the selected item. Is there anyway I can get Element struct from hItem?
3. When you say VS 2003 or 2005 are you referring to only managed managed code?
4. Is RanoRex Opensource to allow others to provide fixes for better and reliable features?

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

Post by admin » Sat Oct 07, 2006 1:34 pm

Stewie wrote:1. The API RxElementFindChild fails to find children for a particular element.
If the function RxElementFindChild() fails, then you should use RanorexSpy to retrieve the correct Role, Name and ClassName of the searched elements. If you use an incorrect argument, the function returns false.
Please study the other (Python, C#) samples and the DumpElementTree function. I'm sorry but we have a poor documentation for C++ user at the moment, you can find some useful information in RanorexNet.chm: Role Enumeration, Selection Enumeration, State Enumeration.
Stewie wrote:2. The TreeView API work to navigate through children, but there is no mechanism to perfom actions on the selected item. Is there anyway I can get Element struct from hItem?


You can use the following functions in C++ for every element (every tree view item) at the moment:

RxElementSelect()
RxElementGetValue()
RxElementSetValue()
RxElementGetState()
RxElementGetDefaultAction()
RxElementDoDefaultAction()
RxElementGetDescription()
RxElementGetHelp()
Stewie wrote:3. When you say VS 2003 or 2005 are you referring to only managed code?

No, all RanorexCore functions should work both with managed and unmanaged code.
Stewie wrote:]4. Is Ranorex Opensource to allow others to provide fixes for better and reliable features?
We try to correct every bug as soon as possible, it's not trivial to automate an application in an other process.
I think we can provide a better quality this way.

Jenö Herget
Ranorex Team