Back to Devexpress

NavigatorBase.ButtonClick Event

windowsforms-devexpress-dot-xtraeditors-dot-navigatorbase.md

latest5.8 KB
Original Source

NavigatorBase.ButtonClick Event

Enables you to perform custom actions when end-users click navigator buttons.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event NavigatorButtonClickEventHandler ButtonClick
vb
<DXCategory("Events")>
Public Event ButtonClick As NavigatorButtonClickEventHandler

Event Data

The ButtonClick event's data class is NavigatorButtonClickEventArgs. The following properties provide information specific to this event:

PropertyDescription
ButtonGets the clicked button.
HandledGets or sets whether you have handled this event and no default action is required.

Remarks

Each button has its default action. For example, the First button’s default behavior is to set the current record to the first record in a data source. This default action is performed each time a user clicks the button. You can however, override the default behavior or perform additional actions when buttons are clicked. Handle the ButtonClick event for this purpose. This event fires each time a navigator button is clicked.

The event’s Button parameter allows you to identify the clicked button. If you want to perform the button’s default action after your event handler is executed, set the event’s Handled parameter to false. To prevent this action from being performed, set the Handled parameter to true.

Example

The following sample code handles the NavigatorBase.ButtonClick event to confirm with the user before deleting a record. A warning message box is shown each time a user presses the Remove button. The user can then click the Yes button to remove the current record or alternatively the No button to cancel deletion of the record.

csharp
using DevExpress.XtraEditors;

private void dataNavigator1_ButtonClick(object sender, NavigatorButtonClickEventArgs e) {
    if (e.Button.ButtonType == NavigatorButtonType.Remove)
        if (MessageBox.Show("Do you really want to delete the record?", "Warning", 
          MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
            e.Handled = true;
}
vb
Imports DevExpress.XtraEditors

Private Sub DataNavigator1_ButtonClick(ByVal sender As Object, _
  ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs) _
  Handles DataNavigator1.ButtonClick
    If e.Button.ButtonType = NavigatorButtonType.Remove Then
        If MessageBox.Show("Do you really want to delete the record?", "Warning", _
          MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
            e.Handled = True
        End If
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the ButtonClick event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-grid-data-navigator-custom-button/CS/CustomButton/Form1.cs#L21

csharp
gridControl1.UseEmbeddedNavigator = true;
gridControl1.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(gridControl1_EmbeddedNavigator_ButtonClick);
gridControl1.EmbeddedNavigator.Buttons.ImageList = imageCollection1;

winforms-data-navigator-bind-to-shared-source/CS/GridProject/Form1.cs#L17

csharp
InitializeComponent();
dataNavigator1.ButtonClick += DataNavigator1_ButtonClick;

winforms-grid-data-navigator-custom-button/VB/CustomButton/Form1.vb#L20

vb
gridControl1.UseEmbeddedNavigator = True
AddHandler gridControl1.EmbeddedNavigator.ButtonClick, New DevExpress.XtraEditors.NavigatorButtonClickEventHandler(AddressOf gridControl1_EmbeddedNavigator_ButtonClick)
gridControl1.EmbeddedNavigator.Buttons.ImageList = imageCollection1

winforms-data-navigator-bind-to-shared-source/VB/GridProject/Form1.vb#L13

vb
InitializeComponent()
    AddHandler dataNavigator1.ButtonClick, AddressOf DataNavigator1_ButtonClick
End Sub

See Also

NavigatorBase Class

NavigatorBase Members

DevExpress.XtraEditors Namespace