Ask a Question

How to check if ribbon IBarItem (a button) is enabled or not (DevExpress WinForms)

SOLVED
mauricekoster
Occasional Contributor

How to check if ribbon IBarItem (a button) is enabled or not (DevExpress WinForms)

Hi,

 

I am trying to get the Enabled status of a ribbon baritem button.

 when trying the following code I get a exception: The object does not support the 'Enabled' member.

 

What am I doing wrong?

 

The code:

 

IBarItem ribbonitem = GetRibbonBarItem(ribbon, "QuickAccessToolbar|Save");   // This function returns the button of interest
var status = ribbonitem.GetProperty<bool>("Enabled");
6 REPLIES 6
AlexKaras
Community Hero

Hi,

 

Can you identify this (or the similar) button in TestLeft's UI Spy. Try to identify the button and check with the Spy if it lists the Enabled property as a member of some supported interface. If the property is listed, try to copy the code to access it using UI Spy (https://support.smartbear.com/testleft/docs/using/creating-tests/accessing-iobject-members.html) and check if it works. If the property is not found, you should consider some other approach (another property or call some native method, etc.)

 

BTW, is your version of DevExpress is supported by TestLeft (https://support.smartbear.com/testleft/docs/general-info/supported-technologies/controls/devexpress....) ?

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
mauricekoster
Occasional Contributor

The RibbonControl which is used is supported in the DevExpress version we use.

 

The problem is that only the ribbon control is visible in TestLeft Spy and not the content of the ribbon (no children visible).

Using programming code I can iterate through the Items collection and get the appropriate button, but the resulting IBarItem interface does not give me any useful methods and properties (except the GetProperty method)

 

Using the Windows Inspect tool (from the Windows SDK Kit) I can see the ribbon and all its children, including the button of interest.

BTW: the property is called 'IsEnabled' in the Inspect tool; changed the code, but problem remains:.

Exception: Additional information: The object does not support the 'IsEnabled' member.

 

All I want is to see is and button on the ribbon control is enabled or not.... How hard can this be?

@HKosova:

Helen,

 

Excuse me..., but can you help with this problem ?

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
HKosova
SmartBear Alumni (Retired)

IBarItem.GetProperty<bool>("Enabled") won't work because IBarItem only has the Text and Items properties and is not linked to the native bar item object in the app.

 

You need to use one of the following:

  1. Access item info using native properties of the ribbon control. Loop through ribbonControl.Items.Item(index) and check the Caption (text label) of each item to find the one you need. Then read the item's Enabled property.

    Alternatively, use ribbonControl.Items.Items_2("name").Enabled where "name" is the item's Name property (you can initially find its value using a loop as explained above).

    All of the above-mentioned properties must be accessed via GetProperty<T>().

  2. Identify ribbon items using MSAA. Add WindowsForms*.Window* to Driver.Options.MSAA as explained here. This should make the buttons show up as individual objects in the UI Spy - similar to what you see in Inspect (Inspect uses MSAA and UI Automation engines). You may need to refresh the UI Spy a couple of times to reflect the changes.

    The ObjectState property of disabled buttons should contain the substring "unavailable".

Hope this helps!

 

Also feel free to submit an enhancement request to have the Enabled property available directly in IBarItem.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

Helen,

 

Thank you a lot for a prompt and pretty informative answer!

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
mauricekoster
Occasional Contributor

Thanks,

 

This helped a lot! Added the driver option opened a lot of (missing) information to the Spy tool. This also helps with other issues I had with other controls...

cancel
Showing results for 
Search instead for 
Did you mean: