Can't iterate through a combo box to get the values

Ask general questions here.
AppTester
Posts: 20
Joined: Thu Sep 29, 2011 12:11 am

Can't iterate through a combo box to get the values

Post by AppTester » Fri Mar 02, 2012 1:52 am

Hi,

I'm trying to iterate through a combo box to get the values in it. I can usually do this with no problem using the following code:

Code: Select all

foreach(Ranorex.Row row in cbxMarket.FindChildren<Ranorex.Row>())
        	{
        		foreach(Ranorex.Cell cell in row.FindChildren<Ranorex.Cell>())
        		{
        			Report.Info(cell.Text);
        		}
        	}
But in this situation I can't get any values. Each time debugging the value of row is null. If I do

Code: Select all

Report.Info(cbxMarket.Children.Count.ToString());
The report states that there are 2.

I've checked with the developer of the program and found out that the combo boxes are regular winform comboboxs. Any suggestions on where I could be going wrong, or some sample code that would work?

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

Re: Can't iterate through a combo box to get the values

Post by Support Team » Fri Mar 02, 2012 8:51 am

Hi,

to get values form a combobox you have to open this combobox by pressing the "Open" button.
That makes a list appear in Ranorex Spy, which holds the values.

Following code snippet will work with the RanorexTestedApp (WinForms) shipped with Ranorex:
Button btn = repo.App.ComboBox.FindSingle("./button");
btn.Click();
List lst = "/list";
foreach (ListItem lst_item in lst.FindChildren<ListItem>())
    Report.Info(lst_item.Text);
Regards,
Tobias
Ranorex Team
.
Image

AppTester
Posts: 20
Joined: Thu Sep 29, 2011 12:11 am

Re: Can't iterate through a combo box to get the values

Post by AppTester » Fri Mar 02, 2012 6:26 pm

Excellent. Thank you for this tip. It works very well for me!