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 wro...
  • HKosova's avatar
    8 years ago

    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.