2

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?

Daniel
  • 1,391
  • 2
  • 19
  • 40

1 Answers1

2

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.

LarsTech
  • 80,625
  • 14
  • 153
  • 225