Back to Devexpress

RepositoryItemButtonEdit.ButtonClick Event

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitembuttonedit-ed843a7f.md

latest9.3 KB
Original Source

RepositoryItemButtonEdit.ButtonClick Event

Occurs when an editor button is clicked.

Namespace : DevExpress.XtraEditors.Repository

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

Handle the ButtonClick event to implement additional functionality when a user clicks an editor button. For example, you can activate a custom drop-down window or dialog, or perform calculations based on entered values.

The ButtonEdit.ButtonClick event is equivalent to the RepositoryItemButtonEdit.ButtonClick event.

ButtonClick fires when:

  • A user releases the pressed button.
  • A user edits the text in the edit box and presses shortcut key(s) assigned to an editor button.

ButtonClick does not fire when:

  • The button is pressed and is not yet released (the RepositoryItemButtonEdit.ButtonPressed event fires).
  • A user presses a button and moves the mouse pointer to another control.
  • A popup editor’s popup is open and a user clicks the drop-down button.

The sender parameter of an event handler is the button edit control that contains the clicked button. Use the e.Button parameter to identify the clicked button. If a user presses shortcut key(s) and several buttons are assigned the same shortcut, the ButtonClick event occurs for all such buttons.

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

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.

xaf-win-custom-button-in-lookup-property-editor/CS/EFCore/LookUpButtonEF/LookUpButtonEF.Win/Editors/MyLookupPropertyEditor.cs#L20

csharp
((RepositoryItemLookupEdit)item).Buttons.Add(new EditorButton(ButtonPredefines.Glyph, "Edit", -1, true, true, true, HorzAlignment.Default, null, new KeyShortcut(System.Windows.Forms.Keys.Enter), appearance, "Press this button to edit the object"));
    ((RepositoryItemLookupEdit)item).ButtonClick += new ButtonPressedEventHandler(MyLookupPropertyEditor_ButtonClick);
}

winforms-property-grid-create-custom-editor/CS/T415077/Form1.cs#L20

csharp
RepositoryItemButtonEdit edit = new RepositoryItemButtonEdit();
edit.ButtonClick += edit_ButtonClick;
(this.propertyGridControl1.Rows[0] as CategoryRow).ChildRows["rowPath2"].Properties.RowEdit = edit;

winforms-pdf-viewer-operate-pdf-content-at-runtime/CS/WindowsFormsApplication1/MainForm.cs#L19

csharp
pdfViewer1.LoadDocument(@"..\..\TextExtraction.pdf");
    repositoryItemButtonEdit3.ButtonClick += repositoryItemButtonEdit3_ButtonClick;
}

winforms-dashboard-custom-items-extension/CS/CustomItemExtension/CustomItems/WebPageItem/WebPageItemExtensionModule.cs#L65

csharp
buttonEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
buttonEdit.ButtonClick += ButtonEdit_ButtonClick;
urlBarItem = new BarEditItem(designer.Ribbon.Manager, buttonEdit);

winforms-property-grid-create-custom-editor/VB/T415077/Form1.vb#L26

vb
Dim edit As RepositoryItemButtonEdit = New RepositoryItemButtonEdit()
AddHandler edit.ButtonClick, AddressOf edit_ButtonClick
TryCast(propertyGridControl1.Rows(0), CategoryRow).ChildRows("rowPath2").Properties.RowEdit = edit

winforms-pdf-viewer-operate-pdf-content-at-runtime/VB/WindowsFormsApplication1/MainForm.vb#L21

vb
pdfViewer1.LoadDocument("..\..\TextExtraction.pdf")
    AddHandler repositoryItemButtonEdit3.ButtonClick, AddressOf repositoryItemButtonEdit3_ButtonClick
End Sub

winforms-dashboard-custom-items-extension/VB/CustomItemExtension/CustomItems/WebPageItem/WebPageItemExtensionModule.vb#L74

vb
buttonEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor
AddHandler buttonEdit.ButtonClick, AddressOf ButtonEdit_ButtonClick
urlBarItem = New BarEditItem(designer.Ribbon.Manager, buttonEdit)

See Also

ButtonClick

ButtonPressed

Shortcut

RepositoryItemButtonEdit Class

RepositoryItemButtonEdit Members

DevExpress.XtraEditors.Repository Namespace