StrataFrame Forum

Maintenance Form Toolstrip not saving button positions

http://forum.strataframe.net/Topic1621.aspx

By Jason Stevenson - 6/21/2006

Guys,

I am trying to add some additional buttons and move the buttons around on the maintenance form toolstrip control.

It appears to save, but after I run the winforms app they are all put back to default positions.

Any ideas?

Jason

By StrataFrame Team - 6/21/2006

The problem comes from the MaintenanceFormToolstrip being a control that has it's own InitializeComponent method... when the designer changes the order of the buttons on the toolstrip, it only changes them on the instance of the toolstrip that is in the designer, but it cannot change them when the form runs.  So, you will most likely need to create a method to swap the order of the buttons programmatically when the form instantiates or loads.  Or, you can subclass the MaintenanceFormToolstrip to create your own and put the logic to swap the buttons in there.  Then, your custom toolstrip will have the correct button order, no matter what form you drop it on.
By Jason Stevenson - 6/22/2006

Thank you.  I apologize for my ignorance, as this is my first WinForms application... 10 years of web programming isn't helping here... Smile
By StrataFrame Team - 6/22/2006

Hehe, WinForms does take some getting used to, but once you're there, it will take all of your energy to drag yourself away from WinForms and back to WebForms... WinForms is just so much more flexible and friendlier Wink
By Jason Stevenson - 6/22/2006

So should we not use the "Edit Items..." option in the upper right menu of the control?

I was able to override the code manually to put things as they should be, but if I use the designer again it of course blows my changes...

Perhaps I should just use a standard toolstrip, but I sure like what you guys have done for speeding up building such a control set...

Thanks again for your help,

Jason

By StrataFrame Team - 6/22/2006

The "Edit Items..." option does move the buttons around within the collection, but since the order is already serialized within the MaintenanceFormToolstrip's InitializeComponent() method, it cannot add code within the Form's InitializeComponent() method that can change the order.  So, you would need a method like this:

private void ReOrderToolStrip()
{
//-- Establish locals
ToolStripButton loNew, loBrowse, loEdit, loDelete, loSave, loUndo;

//-- Save the buttons
loNew = this.maintenanceFormToolStrip1.Items[0];
loBrowse =
this.maintenanceFormToolStrip1.Items[1];
loEdit =
this.maintenanceFormToolStrip1.Items[2];
loDelete =
this.maintenanceFormToolStrip1.Items[3];
loSave =
this.maintenanceFormToolStrip1.Items[4];
loUndo =
this.maintenanceFormToolStrip1.Items[5];

//-- Clear the buttons
this.maintenanceFormToolStrip1.Items.Clear();

//-- Re-add the buttons in the order you want them
this.maintenanceFormToolStrip1.Items.AddRange(new ToolStripItem[]
{ loSave, loUndo, loNew, loEdit, loDelete, loBrowse });
}

You'll also need to add any ToolStripSeparators you want.

By StrataFrame Team - 6/22/2006

What I will do, is look into the possibility of adding properties that will allow you to set the order of the buttons.
By Jason Stevenson - 6/22/2006

As usual you guys have the answers.  Thanks again for the sample code.

Jason

By StrataFrame Team - 6/22/2006

If we don't have the answers, then Google does Wink