We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to copy the column and paste it as a new column by ContextMenu in SfDataGrid?

SfDataGrid provides support for ContextMenu interactive feature that is used to show the customizable menu for various parts of the SfDataGrid. You can show the ContextMenu in ColumnHeader by using the HeaderContextMenu.

The CopyColumn and PasteColumn menu items are added as Collection of MenuItem to ItemsSource of ContextMenu of the SfDataGrid.

The following code example illustrates to add the Menu Items into ContextMenu in SfDataGrid and to use single command for all MenuItems.

XAML

Figure 1: ContextMenu added to the Column Header

The following code example illustrates the command for the above menu items, CopyColumn and PasteColumn to perform the copy and paste actions in column.

C#

While clicking on HeaderContextMenu, MyCommand gets triggered with parameter GridColumnContextMenuInfo that contains the following information,

Column: Information about the column.

DataGrid: The instance of SFDataGrid.

From GridColumnContextMenuInfo, corresponding column is assigned to temporary variable as a GridColumn type when copy is performed and it is inserted into next index position when the paste option is clicked on HeaderContextMenu.

Figure 2: RollNo is pasted as a New Column

You can refer the sample from the below location.

WPF

 

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework:
3245 01/19/2015 09/29/2016 WPF SfDataGrid 4.5
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.