Christian Torres M Christian Torres M - 3 months ago 24
C# Question

How to add two ToolStripComboBox and Separator Horizontally to one ToolStripDropMenuItem?

I think that this should be simple to do. But I haven't seen it. I'd like to do something like:

DropDown -> DropDownItem1 [ComboBox1 [|] ComboBox2], DropDownItem2 [...], DropDownItem3 [...];

I'm using ToolStripDropDownButton in a ToolStrip. I'm programming w/ C# . Thanks for your advices.

Something like:

Best Regards


It seems you are looking for such layout:

enter image description here

To do so, you don't need to create any custom control. Just use common features of ToolStrip. You need to set the LayoutStyle property to a suitable value.


private void Form1_Load(object sender, EventArgs e)
    var dropdown = new ToolStripDropDown();

    //Define style
    dropdown.LayoutStyle = ToolStripLayoutStyle.Table;
    var settings = (dropdown.LayoutSettings as TableLayoutSettings);
    settings.ColumnCount = 3;

    //First Item    
    var item1 = new ToolStripMenuItem("Some Sub Menu");
    settings.SetColumnSpan(item1, 3); //Set column span to fill the row

    //First Combo
    var combo1 = new ToolStripComboBox("combo1");
    combo1.Items.AddRange(new string[] { "Item1", "Item2", "Item3" });


    //Second Combo
    var combo2 = new ToolStripComboBox("combo2");
    combo2.Items.AddRange(new string[] { "Item1", "Item2", "Item3" });

    //Last item
    var item2 = new ToolStripMenuItem("Some Othe Sub Menu");
    settings.SetColumnSpan(item2, 3); //Set column span to fill the row

    toolStripDropDownButton1.DropDown = dropdown;