Cant find toolbar buttons within a custom PropertyGrid

Class library usage, coding and language questions.
alfred wertner
Posts: 2
Joined: Mon Oct 27, 2008 10:48 am

Cant find toolbar buttons within a custom PropertyGrid

Post by alfred wertner » Mon Oct 27, 2008 12:56 pm

The custom property grid inherits from .net framework PropertyGrid class and is embedded in a tab control.
It works to find the control with:
Ranorex.TabControl tabControl = Common.ChangeTabPage("Sources");
Control propertyGrid = tabControl.FindChildText("PropertyGrid");

Inside the grid there is a toolstrip control with 4 buttons. I cant find the buttons. I tried different ways, but none of them worked, e.g.

// returns a null reference
Control toolbar = propertyGrid.FindControlName("ToolBar");
Control btnAdd = toolbar.FindControlName("Add");

I am using Ranorex v1.5

Thanks a lot!

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

Post by Support Team » Mon Oct 27, 2008 2:12 pm

Have you inspected the property grid with RanorexSpy?

If your property grid works like the default one, then the toolbar does not have a control name and the buttons are no controls, but elements. In that case you need to search for the toolbar by classname or control text (Control.FindChildText() method). And the buttons are usually represented by elements, so an Element.FindChild("Add") statement should work.

Regards,
Alex
Ranorex Support Team

alfred wertner
Posts: 2
Joined: Mon Oct 27, 2008 10:48 am

Post by alfred wertner » Tue Oct 28, 2008 2:17 pm

Yes, I did.

I get a reference of the toolbar with the FindChildText() Method. That works so far.

toolbar.Element.FindChild("add") does not exist.

I tried to get the buttons callling FindChild(Role.Pushbutton, "Add"), without success.

With FindClassName() i am not sure what control i actually get because the grid, the toolbar and the buttons have the same class name and instance number. However, i get some control but calling FindChild with the same parameters as above also fails.

Regards,
Alfred.

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

Post by Support Team » Wed Oct 29, 2008 1:15 pm

alfred wertner wrote:With FindClassName() i am not sure what control i actually get because the grid, the toolbar and the buttons have the same class name and instance number.
All .NET controls (except for special ones like ComboBox) have the same classname. So using the classname to search for a specific .NET control is not a good idea. The ControlName is a much better choice.

From your description I assume that this is not a Ranorex bug, but some application/control that is difficult to automate. If you send us a sample of that PropertyGrid and a description of what you're trying to achieve, I will try to compile a short Ranorex example for you.

Regards,
Alex
Ranorex Support Team

emu
Posts: 3
Joined: Mon Jul 17, 2006 3:45 pm
Contact:

Post by emu » Thu Oct 30, 2008 11:59 am

Hi Alex!
Thanks for the quick help!

This runs perfectly now:

Code: Select all

Ranorex.Element addButton = null;
Control tabControl = null;
Control tabPage = null;
Control propertyGridToolBar = null;
tabControl=TubeBuilder.FormApp.FindTabControl("tabControlBuildingBlockStructureHandler");
tabControl.SelectedText = "Sources";
tabPage = tabControl.FindChildText("Sources");
propertyGridToolBar = tabPage.FindChildText("PropertyGridToolBar");
addButton =propertyGridToolBar.Element.FindChild(Role.PushButton, "Add");[