ComboBox Items Collection count is 0 for VB6 combo box.

Ask general questions here.
mohan
Posts: 9
Joined: Tue Aug 09, 2011 11:54 am

ComboBox Items Collection count is 0 for VB6 combo box.

Post by mohan » Thu Aug 11, 2011 11:26 am

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

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

Post by Support Team » Thu Aug 11, 2011 2:08 pm

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
.
Image

mohan
Posts: 9
Joined: Tue Aug 09, 2011 11:54 am

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

Post by mohan » Fri Aug 12, 2011 2:45 pm

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
Attachments
Attachement.zip
please refer the attachemt
(314.31 KiB) Downloaded 198 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

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

Post by Support Team » Mon Aug 15, 2011 1:19 pm

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
.
Image

mohan
Posts: 9
Joined: Tue Aug 09, 2011 11:54 am

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

Post by mohan » Thu Aug 18, 2011 1:54 pm

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.