Skip to main content

How to: Respond to Clicking ButtonEdit's Embedded Buttons

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.

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();
    }
  }
}