0

How can I programmatically create a ToolStripDropDown in a winform project ? I want to associate this item to a TextBox (showing last entries) and it appears when clicking on a Button.

It should be on the red line :

enter image description here

Edit : I actually have :

Class MyClass : UserControl
{
    //Created in designer :
    // Button buttonName;
    // TextBox textboxName;
    // List<String> lastNames;

    // I want to create
    ToolStripDropDown toolStripName;

    public MyClass ()
    {
        toolStripName = new ToolStripDropDown();
        toolStripName.OwnerItem = textboxName; // Want to define the textbox as owner
        buttonName.Click += ButtonName_Click;
        toolStripName.Items = lastNames; // I want to display the last names saved
    }

    private void ButtonName_Click(object sender, EventArgs e)
    {
        toolStripName.Show();
    }
}

This code doesn't work. I never used a ToolStripDropDown and I don't know how to use it.

A.Pissicat
  • 3,023
  • 4
  • 38
  • 93
  • You have to show us code that duplicates it for us. – LarsTech Mar 20 '17 at 16:13
  • What is the nature of the problem you are encountering? Your question is too general at the moment – SpaceUser7448 Mar 20 '17 at 16:16
  • Actually I just have a `Button buttonName` and a `TextBox textBoxName`. I want to create a `ToolStripDropDown` element. This element appears on the box bot when clicking on button. It will contain a list of string. – A.Pissicat Mar 20 '17 at 16:17
  • @SpaceUser7448 I added my actual code to be less general, but it is a draft. – A.Pissicat Mar 20 '17 at 16:26
  • OwnerItem has to be a ToolStrip item, so that can't be a normal TextBox control. Is that a standard button or a ToolStrip button? Why not use a ToolStripDropDownButton instead? – LarsTech Mar 20 '17 at 16:39
  • @LarsTech I did some researches and I found ToolStripDropDown, I don't know the difference with ToolStripDropDownButton. I'll take a look – A.Pissicat Mar 20 '17 at 16:52

0 Answers0