Page 1 of 1

ComboBox Items Collection count is 0 for VB6 combo box.

Posted: Thu Aug 11, 2011 11:26 am
by mohan
Hello,

I'm facing problem in Combobox Item selection.

The application under test is developed using VB6.0. I can able to spy combo boxes without any issues or conflicts. But the problem is it always gives the item collection count as 0.
For selecting an item I’ve to do like below:

//Code Snippet
Ranorex.ListItem ComboBoxListItem;

bool bItemFound = combo.TryFindSingle<ListItem>("//item[@text~'text_to_select']",out ComboBoxListItem);

if (bItemFound && ComboBoxListItem != null)
{
ComboBoxListItem.Click();
}
Is there any way to get the Item Collection of Visual Basic 6.0 Combo?

Re: ComboBox Items Collection count is 0 for VB6 combo box.

Posted: Thu Aug 11, 2011 2:08 pm
by Support Team
Hi,

Please try to use
".//item[@text~'text_to_select']"
isntead of
"//item[@text~'text_to_select']"
maybe Ranorex takes to long to find the specific elements if you use the "//", exceeds the timeout. Therefore use the ".//", the difference is that with the dot Ranorex searches for all the descendants of the current element, in your case of the combo element; whereas "//" searches from the very root of the element tree.

Regards,
Markus
Ranorex Support Team

Re: ComboBox Items Collection count is 0 for VB6 combo box.

Posted: Fri Aug 12, 2011 2:45 pm
by mohan
Hi Markus,
Appreciate your answer. I changed the code as per your suggestion to select an item and it works. But my original question was : Why am I not getting the "Items" Property collection of comboBox adapter? For your information I am attaching a document which is having screen shots that shows the combobox which I spyed and also showing the code which I wrote to access the Items Collection, with description.

I am using Ranorex Version 3.0.2.


Regards,
Mohan

Re: ComboBox Items Collection count is 0 for VB6 combo box.

Posted: Mon Aug 15, 2011 1:19 pm
by Support Team
Hi,
mohan wrote: Why am I not getting the "Items" Property collection of comboBox adapter?
Combobox Items are very special indeed. In most cases the collection of the list items is nested directly under the host, therefore you need the instant tracking of Ranorex Spy.
Did you try instant tracking on the listitems of the combobox?
How to use Instant Tracking
If not please try it and for sure you will find a list with your items in it. The behavior of a combobox depends on the technology you use. Sometimes you can access the items directly under the control and sometimes you have the behavior above.

BTW, Ranorex 3.0.5 is released and it is very recommended to upgrade to this version.
http://www.ranorex.com/download/Ranorex-3.0.5.exe

Regards,
Peter
Ranorex Team

Re: ComboBox Items Collection count is 0 for VB6 combo box.

Posted: Thu Aug 18, 2011 1:54 pm
by mohan
I got the solution but I did not try "instant tracking". The combo Box Item collection is populated with Items only when it is Visible in UI. If I click on the combo and then checks the Count then I’m getting the collection. The code is something like below:

objShipment.FormShipment.cmbFrom.Click();
if (objShipment.FormShipment.cmbFrom.Items.Count > 0)
objShipment.FormShipment.cmbFrom.Items[2].Click();

The above behaviour exists with Microsoft Combo box as well.BTW, thanks for supporting all the way to reach the solution.