1

I want to extend the BindingNavigator so I can add extra functionality to it. One of the things I want to do is add a ToolStripSplitButton that will autosize the cells in a DataGridView. I've been able to add the button, but when I drop the control on a form, my button is in the first position. I would like to add this button after the Delete button. How can I do this?

Here is what the control looks like when dropped onto a form at design time: nav

Here is the code:

public class DataGridToolStrip : BindingNavigator
{

    private ToolStripSplitButton AutoSizeButton;
    private ToolStripMenuItem mnuAllCells;
    private ToolStripMenuItem mnuAllCellsExceptHeader;
    private ToolStripMenuItem mnuColumnHeader;
    private ToolStripMenuItem mnuDisplayedCells;
    private ToolStripMenuItem mnuDisplayedCellsExceptHeader;

    public DataGridToolStrip() : base(false)
    {
        //this.Items.Clear();
        //this.AddStandardItems();

        this.mnuAllCells = new ToolStripMenuItem();
        this.mnuAllCellsExceptHeader = new ToolStripMenuItem();
        this.mnuColumnHeader = new ToolStripMenuItem();
        this.mnuDisplayedCells = new ToolStripMenuItem();
        this.mnuDisplayedCellsExceptHeader = new ToolStripMenuItem();
        this.AutoSizeButton = new ToolStripSplitButton();

        this.AutoSizeButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
        this.AutoSizeButton.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.mnuAllCells,
        this.mnuAllCellsExceptHeader,
        this.mnuColumnHeader,
        this.mnuDisplayedCells,
        this.mnuDisplayedCellsExceptHeader});

        this.AutoSizeButton.Name = "AutoSizeButton";
        this.AutoSizeButton.Size = new System.Drawing.Size(72, 22);
        this.AutoSizeButton.Text = "Auto Size";



        this.Items.Add(AutoSizeButton);
    }
}
Jeff
  • 908
  • 2
  • 9
  • 23
  • Have you tried to add your AutoSizeButton as the last into the array of controls passed to DropDownItems.AddRange ? – hypnos Dec 10 '16 at 18:03

1 Answers1

1

You can override AddStandardItems method of BindingNavigator and and add additional items after calling base.AddStandardItems():

public class DataGridToolStrip : BindingNavigator
{
    public override void AddStandardItems()
    {
        base.AddStandardItems();
        // Add addtional items here
    }
}
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398