Ribbon ComboBox: Clear/Change Data

Ribbon ComboBox: Clear/Change Data

Anonymous
Not applicable
3,294 Views
11 Replies
Message 1 of 12

Ribbon ComboBox: Clear/Change Data

Anonymous
Not applicable

Hello all,

 

I have a ComboBox that I've created and inserted into a custom Ribbon Tab. On document open, I populate the contents of the ComboBox with a list of 3d views. Everything works great. However, if I were to close that project and open another, I cannot seem to find a way to clear the previous data in the ComboBox. Ideally I'd like to do this when I receive the DropDownOpened callback, to catch any new/deleted views. I am using the 2014 SDK.

 

Thanks

Shane

0 Likes
Accepted solutions (1)
3,295 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable

A little clarification:

This is an Autodesk.Revit.UI.ComboBox that I'm using. The member functions contain AddItem and AddItems, but no RemoveItem or Clear.

0 Likes
Message 3 of 12

Revitalizer
Advisor
Advisor
Accepted solution

Dear scolliatie,

 

since you cannot remove items from the combobox, you need to use a workaround.

 

First, fill your combobox with dummy entries, say 50 to make sure there are enough slots for your 3D views.

 

Then, set the *visibility* property of each item to simulate a dynamic list.

You also can replace both the text and the image at runtime.

 

You just need to adjust the existing combobox items according to your own element list.

If your element list is shorter than 50, all remaining combobox items must be made invisible.

If it is longer than 50, then 50 slots aren't enough 😉

 

This approach will also work for DropDownButtons.

 

 

Best regards,

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 12

0001des
Enthusiast
Enthusiast

Is there any progress on enhancing ribbon comboboxes and other items to handle "remove" "replace" and "Clear?"

0 Likes
Message 5 of 12

Revitalizer
Advisor
Advisor

No - Revit 2019 API does not provide a "RemoveItem" method.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 6 of 12

0001des
Enthusiast
Enthusiast

I know there isn't a "remove," "clear," or "insert" method.  I'm basically bumping this thread after several years of waiting.

Message 7 of 12

Revitalizer
Advisor
Advisor

Hi,

 

then please submit an idea or vote up an existing one that matches your needings:

 

https://forums.autodesk.com/t5/revit-ideas/idb-p/302/tab/most-recent

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 8 of 12

TheRealChrisHildebran
Advocate
Advocate

I submitted another request for this on the Idea board.

 

https://forums.autodesk.com/t5/revit-ideas/ability-to-remove-combobox-item/idi-p/9553581

0 Likes
Message 9 of 12

Kennan.Chen
Advocate
Advocate

Since the UI API designed in RevitAPIUI.dll is actually a wrapper around some basic UI controls design in AdWindows.dll. There are two choices for you.

1. Use the undocumented APIs in AdWindows.dll to create your combobox to gain a full access to all the functionalities.

2. Use the documented APIs in RevitAPIUI.dll to create the combobox. Then use reflection to get the wrapped AdWindows UI control and modify it.

Both of the two approaches require an understanding of the undocumented APIs in AdWindows.dll. You may use open source hack tools to uncover it from the dll or just reply on the Visual Studio intellisense to explore yourself.

Message 10 of 12

Anonymous
Not applicable

Hello.

 

Could you give an example of initializing or deleting ribbon combobox items using AdWindow?

I know how to get to Autodesk.Windows.RibbonItem.

0 Likes
Message 11 of 12

Kennan.Chen
Advocate
Advocate

Actually I have some really old code out there on github. Hope it helps! 🙂

 

https://github.com/KennanChan/RevitAPIToolbox/blob/master/RevitAPIToolbox/UI/UIFactory.cs

 

For deleting RibbonItems, the RibbonPanel.Source.Items should provide a Remove method

0 Likes
Message 12 of 12

Anonymous
Not applicable

Thanks.

 

I got a hint and I can control the combo box.

Below is the code I tested and made.
It actually works!

 

                var tabRibbon = ComponentManager.Ribbon.FindTab($"{Common.TabNameTest}");
                if (UIApp.GetRibbonPanels(tabRibbon.Name).FirstOrDefault(x => x.Name.Equals(Common.PanelNameTest)) is Autodesk.Revit.UI.RibbonPanel panel)
                {
                    if(tabRibbon.FindItem($"CustomCtrl_%CustomCtrl_%{tabRibbon.Name}%{panel.Name}%LevelsSelector") is RibbonList comboList)
                    {
                        //comboList
                        var addItem = new Autodesk.Windows.RibbonItem
                        {
                            Id = $"CustomCtrl_%CustomCtrl_%CustomCtrl_%{tabRibbon.Name}%{panel.Name}%LevelsSelector%AddLevelTest",
                            Text = "AddLevelTest"
                        };

                        var firstItem = comboList.Items.FirstOrDefault(x => (x as Autodesk.Windows.RibbonItem).Text.Equals("Level 1"));

                        comboList.Items.Remove(firstItem);
                        comboList.Items.Clear();
                        comboList.Items.Add(addItem);
                    }
                }

 

Here, when the first value of the combo box is removed, Current becomes blank and an exception appears in the Current variable of Autodesk.Revit.UI.ComboBox.

Be careful.

.