Example E1127
Visible to All Users

WinForms Data Grid - Create a custom button for the embedded navigator

This example demonstrates how to create a custom button and display it in the grid's data navigator.

C#
private void Form1_Load(object sender, EventArgs e) { // ... gridControl1.UseEmbeddedNavigator = true; gridControl1.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(gridControl1_EmbeddedNavigator_ButtonClick); gridControl1.EmbeddedNavigator.Buttons.ImageList = imageCollection1; DevExpress.XtraEditors.NavigatorCustomButton button = gridControl1.EmbeddedNavigator.Buttons.CustomButtons.Add(); button.Tag = "copy"; button.Hint = "Copy to clipboard"; button.ImageIndex = 0; } private void gridControl1_EmbeddedNavigator_ButtonClick(object sender, DevExpress.XtraEditors.NavigatorButtonClickEventArgs e) { if("copy".Equals(e.Button.Tag)) { if(gridControl1.FocusedView != null) { gridControl1.FocusedView.CopyToClipboard(); MessageBox.Show("Selected data has been copied to the Clipboard"); e.Handled = true; } } }

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

CustomButton/Form1.cs(vb)
C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace CustomButton { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // load some demo data new DevExpress.XtraGrid.Design.XViewsPrinting(gridControl1); gridView1.OptionsSelection.MultiSelect = true; gridControl1.UseEmbeddedNavigator = true; gridControl1.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(gridControl1_EmbeddedNavigator_ButtonClick); gridControl1.EmbeddedNavigator.Buttons.ImageList = imageCollection1; DevExpress.XtraEditors.NavigatorCustomButton button; button = gridControl1.EmbeddedNavigator.Buttons.CustomButtons.Add(); button.Tag = "copy"; button.Hint = "Copy to clipboard"; button.ImageIndex = 0; } private void gridControl1_EmbeddedNavigator_ButtonClick(object sender, DevExpress.XtraEditors.NavigatorButtonClickEventArgs e) { if("copy".Equals(e.Button.Tag)) { if(gridControl1.FocusedView != null) { gridControl1.FocusedView.CopyToClipboard(); MessageBox.Show("Selected data has been copied to the Clipboard"); e.Handled = true; } } } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.