Skip to main content

How to: Create ButtonEdit Control in Code

  • 2 minutes to read

The following code snippet creates a ButtonEdit control, customizes its buttons, and places the editor onto the form:

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

namespace DXApplication {
    public partial class Form1 : XtraForm {
        public Form1() {
            InitializeComponent();

            // Create a `ButtonEdit` and add it to the form.
            ButtonEdit btnEdit1 = new ButtonEdit() {
                Width = 200
            };

            // Configure the default (first) button as an OK button.
            btnEdit1.Properties.Buttons[0].Kind = ButtonPredefines.OK;

            // Add an additional button and treat it as a Delete action.
            btnEdit1.Properties.Buttons.Add(new EditorButton(ButtonPredefines.Delete));

            // Add the editor to the form's controls collection.
            this.Controls.Add(btnEdit1);

            // Handle button clicks.
            btnEdit1.ButtonClick += BtnEdit1_ButtonClick;
        }
        void BtnEdit1_ButtonClick(object sender, ButtonPressedEventArgs e) {
            ButtonEdit editor = sender as ButtonEdit;
            if (e.Button.Kind == ButtonPredefines.OK) {
                // OK button pressed.
                //...
            }
            if (e.Button.Kind == ButtonPredefines.Delete) {
                // Delete button pressed.
                //...
            }
        }
    }
}