Add object other than string to ToolStripDropDownButton DropDownItem
-
22-06-2021 - |
Question
It's easy to add strings to a ToolStripDropDownButton as a new DropDownItem. What I need is to add a custom object to the DropDownItems so that I can assign a key/value like object to the DropDownItem.
How may I achieve this?
Solution
ToolStripItems can only display text and images and don't take objects. You can try sneaking an object in the Tag property of the button:
ToolStripDropDownButton b = new ToolStripDropDownButton();
b.DropDownItems.Add(new ToolStripButton("Hello") { Tag = new Something() });
and then when you handle the click event, inspect the Tag property for your object.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow