Skip to main content

RepositoryItemButtonEdit Class

An object that contains settings specific to a ButtonEdit control. Repository items allow you to embed editors into container controls (for instance, GridControl, TreeList, RibbonControl).

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v25.2.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

public class RepositoryItemButtonEdit :
    RepositoryItemTextEdit

The following members return RepositoryItemButtonEdit objects:

Remarks

A RepositoryItemButtonEdit object contains properties, methods, and events related to a ButtonEdit control.

Standalone Editors

If you use a standalone ButtonEdit control, its ButtonEdit.Properties property returns a RepositoryItemButtonEdit instance. You can access this object to customize the editor’s settings.

RepositoryItemButtonEdit

The following example adds a button to a standalone ButtonEdit control, and handles the ButtonClick event to respond to button clicks.

ButtonEdit-example

using DevExpress.XtraEditors.Repository;

RepositoryItemButtonEdit properties = buttonEdit1.Properties;
properties.Buttons.Clear();
properties.Buttons.Add(new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Close));
properties.ButtonClick += Properties_ButtonClick;

private void Properties_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) {
    if(e.Button.Kind==DevExpress.XtraEditors.Controls.ButtonPredefines.Close) {
        //...
    }
}

In-place Editors

For each editor that can be embedded in a composite control (for instance, GridControl, TreeList, RibbonControl) the DevExpress Editors library has a corresponding repository item (a RepositoryItem descendant).

Create a RepositoryItemButtonEdit object to embed a ButtonEdit control into such a composite control. See the following topic for more information: Editors and Simple Controls.

Example - Create Inplace Editor

The following example creates a ButtonEdit with a Copy button and uses the editor within the Data Grid control to edit cell values in the Description column. The Data Grid control and SVG Image Collection are created at design time.

WinForms Data Grid and Button Editor, DevExpress

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid;
using System.ComponentModel;
using System.Windows.Forms;

namespace DXApplication {
    public partial class Form1 : XtraForm {
        BindingList<DataItem> dataItems;
        RepositoryItemButtonEdit inplaceButtonEdit;
        public Form1() {
            InitializeComponent();

            // Data source for the grid.
            dataItems = new BindingList<DataItem>() {
                new DataItem() { Id = 1, CategoryName = "Category 1", Description = "Description 1" },
                new DataItem() { Id = 2, CategoryName = "Category 2", Description = "Description 2" },
                new DataItem() { Id = 3, CategoryName = "Category 3", Description = "Description 3" }
            };
        }

        void Form1_Load(object sender, System.EventArgs e) {
            // Bind the grid to data.
            grid.DataSource = dataItems;

            // Ensure the grid and its views/columns are created before accessing `MainView` and columns.
            grid.ForceInitialize();

            var view = grid.MainView as GridView;

            if(view == null)
                return;

            // Create an in-place button editor for the Description column.
            inplaceButtonEdit = new RepositoryItemButtonEdit();

            // Configure the first (default) button to show a glyph (SVG icon) and mark it as "Copy".
            inplaceButtonEdit.Buttons[0].Kind = ButtonPredefines.Glyph;
            inplaceButtonEdit.Buttons[0].Tag = "Copy";
            inplaceButtonEdit.Buttons[0].ImageOptions.SvgImage = svgImageCollection1["copy"];
            inplaceButtonEdit.Buttons[0].ImageOptions.SvgImageSize = new System.Drawing.Size(16, 16);

            // Handle button clicks.
            inplaceButtonEdit.ButtonClick += InplaceButtonEdit_ButtonClick;

            // Register the repository item.
            grid.RepositoryItems.Add(inplaceButtonEdit);

            // Assign the editor to the 'Description' column.
            view.Columns["Description"].ColumnEdit = inplaceButtonEdit;
        }

        void InplaceButtonEdit_ButtonClick(object sender, ButtonPressedEventArgs e) {
            var view = grid.MainView as GridView;

            if (e.Button.Tag != null && e.Button.Tag.ToString() == "Copy") {
                // Copy the Description of the focused row to the clipboard.
                int rowHandle = view.FocusedRowHandle;
                DataItem item = view.GetRow(rowHandle) as DataItem;
                if (item != null) {
                    Clipboard.SetText(item.Description);
                }
            }
        }
    }

    public class DataItem {
        public int Id { get; set; }
        public string CategoryName { get; set; }
        public string Description { get; set; }
    }
}
See Also