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
Solved! Go to Solution.
Solved by Revitalizer. Go to Solution.
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.
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
Is there any progress on enhancing ribbon comboboxes and other items to handle "remove" "replace" and "Clear?"
No - Revit 2019 API does not provide a "RemoveItem" method.
Revitalizer
I know there isn't a "remove," "clear," or "insert" method. I'm basically bumping this thread after several years of waiting.
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
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
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.
Hello.
Could you give an example of initializing or deleting ribbon combobox items using AdWindow?
I know how to get to Autodesk.Windows.RibbonItem.
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
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.
.