Back to Devexpress

ButtonEdit.ButtonClick Event

windowsforms-devexpress-dot-xtraeditors-dot-buttonedit-2d78c22d.md

latest4.5 KB
Original Source

ButtonEdit.ButtonClick Event

Occurs when a button editor’s button is clicked.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

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

Event Data

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

PropertyDescription
ButtonGets the button being pressed/clicked.

Remarks

Use this event to perform actions when a user clicks an editor button. You can, for instance, activate a custom dropdown window, a dialog or perform calculations based on a value entered etc.

The editor’s ButtonClick event is equivalent to the RepositoryItemButtonEdit.ButtonClick event available via the ButtonEdit.Properties object, i.e. adding/removing an event handler for the current event actually affects the RepositoryItemButtonEdit.ButtonClick event.

Refer to the RepositoryItemButtonEdit.ButtonClick topic for more information.

Example

In this example, the form contains a ButtonEdit control added at design time.

The following code snippet adds buttons to the ButtonEdit and handles the ButtonClick event to respond to clicks on these buttons.

csharp
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;

namespace DXApplication6 {
  public partial class Form1 : DevExpress.XtraEditors.XtraForm {
    public Form1() {
    InitializeComponent();
    buttonEdit1.Properties.Buttons.Add(new EditorButton("message", ButtonPredefines.Ellipsis));
    buttonEdit1.Properties.Buttons.Add(new EditorButton("message", ButtonPredefines.Search));
    buttonEdit1.Properties.Buttons.Add(new EditorButton(ButtonPredefines.Clear));
    buttonEdit1.ButtonClick += ButtonEdit1_ButtonClick;
    }

    private void ButtonEdit1_ButtonClick(object sender, ButtonPressedEventArgs e) {
      if (e.Button.Tag?.ToString() == "message")
        XtraMessageBox.Show($"{e.Button.Kind} button clicked.", "Information");
      if (e.Button.Kind == ButtonPredefines.Clear)
        ((ButtonEdit)sender).Clear();
    }
  }
}
vb
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls

Namespace DXApplication6
  Partial Public Class Form1
      Inherits DevExpress.XtraEditors.XtraForm

    Public Sub New()
    InitializeComponent()
    buttonEdit1.Properties.Buttons.Add(New EditorButton("message", ButtonPredefines.Ellipsis))
    buttonEdit1.Properties.Buttons.Add(New EditorButton("message", ButtonPredefines.Search))
    buttonEdit1.Properties.Buttons.Add(New EditorButton(ButtonPredefines.Clear))
    AddHandler buttonEdit1.ButtonClick, AddressOf ButtonEdit1_ButtonClick
    End Sub

    Private Sub ButtonEdit1_ButtonClick(ByVal sender As Object, ByVal e As ButtonPressedEventArgs)
      If e.Button.Tag?.ToString() = "message" Then
        XtraMessageBox.Show($"{e.Button.Kind} button clicked.", "Information")
      End If
      If e.Button.Kind = ButtonPredefines.Clear Then
        DirectCast(sender, ButtonEdit).Clear()
      End If
    End Sub
  End Class
End Namespace

See Also

ButtonClick

ButtonPressed

ButtonEdit Class

ButtonEdit Members

DevExpress.XtraEditors Namespace