|
|
C#:
private void ConfigureUndoSplitButton() {
ToolStripItemCollection dropDownItems =
Page.UndoSplitButton.DropDownItems;
ToolStripItem item;
item = dropDownItems.Add("Undo
All");
item.Click += UndoAllHandler;
SetUndoButtonDefaultItem(item);
// initial default.
item = dropDownItems.Add("Undo
Current");
item.Click += UndoCurrentHandler;
}
private void SetUndoButtonDefaultItem(ToolStripItem
item) {
ToolStripSplitButton button = Page.UndoSplitButton;
button.DefaultItem = item;
button.Text = item.Text;
//
ToDo: handle item images if decide to use them.
}
private void UndoAllHandler(object sender,
EventArgs e) {
ToolStripItem item = (ToolStripItem)sender;
SetUndoButtonDefaultItem(item);
PerformUndo(item.Text, GetAllChangedEmployees());
}
VB.NET:
Private Sub ConfigureUndoSplitButton()
Dim dropDownItems As ToolStripItemCollection = _
Page.UndoSplitButton.DropDownItems
Dim item As ToolStripItem
item = dropDownItems.Add("Undo
All")
AddHandler item.Click, AddressOf UndoAllHandler
SetUndoButtonDefaultItem(item) ' initial default.
item = dropDownItems.Add("Undo
Current")
AddHandler item.Click, AddressOf UndoCurrentHandler
End Sub
Private Sub SetUndoButtonDefaultItem(ByVal item As ToolStripItem)
Dim button As ToolStripSplitButton = Page.UndoSplitButton
button.DefaultItem = item
button.Text = item.Text
'
ToDo: handle item images if decide to use them.
End Sub
Private Sub UndoAllHandler( _
ByVal sender As Object, ByVal e As EventArgs)
Dim item As ToolStripItem = CType(sender, ToolStripItem)
SetUndoButtonDefaultItem(item)
PerformUndo(item.Text, GetAllChangedEmployees())
End Sub
|
|
Remember: Pressing a ToolStrip button does not complete a currently
open data binding action. The user’s last data entry could be lost.
This does not matter for undo – we are going to discard pending changes anyway.
But if this were a different button – a Save button, for example – we
would have to close the uncompleted binding explicitly by calling Page.Validate() in each of the handlers.
Check out our other Tech Tips for the full story on this issue and for other nifty
clues to programming .NET applications.
|