Forum Discussion

mauricekoster's avatar
mauricekoster
Occasional Contributor
8 years ago

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");
  • 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.

  • HKosova's avatar
    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.

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Helen,

       

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

    • mauricekoster's avatar
      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...

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    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.html) ?

    • mauricekoster's avatar
      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?