I add strings (items) dynamically to a ToolStripItemCollection by:
Dim onClickHandler As System.EventHandler = New System.EventHandler(AddressOf Symbol_Click)
Dim item As New ToolStripMenuItem(newSymbol, Nothing, onClickHandler)
SomeToolStripMenuItem.DropDownItems.Add(item)
So the items are not added in one go, but one-by-one based on external triggers throughout the program session. I would like to sort the drop-down-list every time I add a new item. What are my options to achieve that?
Since
ToolStripItemCollection
has no "Sort"-Function, you have to listen on changes and write your own sort-method:You have to use your own comparer (https://learn.microsoft.com/en-us/dotnet/api/system.collections.arraylist.sort)