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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WPF |
Control: SfDataGrid |
.NET Framework: 4.5

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.


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.


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.



2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon

Live Chat Icon For mobile