Christian Torres M Christian Torres M - 1 month ago 11
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: https://s18.postimg.org/nd9r35jpl/c89a195a3b6e8dac6e7753af6b0b8a6c.png

Best Regards

Answer

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.

Example

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");
    dropdown.Items.Add(item1);
    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" });
    dropdown.Items.Add(combo1);

    //Separator
    dropdown.Items.Add("-");

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

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

    toolStripDropDownButton1.DropDown = dropdown;
}
Comments