diff --git a/CopyingUsingContextMenu.png b/CopyingUsingContextMenu.png new file mode 100644 index 0000000..dd7ce17 Binary files /dev/null and b/CopyingUsingContextMenu.png differ diff --git a/PastingUsingContextMenu.png b/PastingUsingContextMenu.png new file mode 100644 index 0000000..f19cc25 Binary files /dev/null and b/PastingUsingContextMenu.png differ diff --git a/README.md b/README.md index 90672c2..d57f8ed 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,61 @@ -# How to copy a column and paste it as a new column in wpf treegrid? -This sample illustrates how to copy a column and paste it as a new column in wpf treegrid +# How to Copy a Column and Paste it as a New Column in WPF TreeGrid? + +This sample illustrates how to copy a column and paste it as a new column in [WPF TreeGrid](https://www.syncfusion.com/wpf-controls/treegrid) (SfTreeGrid). + +You can copy a column and paste it into a new position using the context menu option in TreeGrid. + +### XAML + +``` xml + + + + + + + +``` + +### C# + +``` c# +private static void OnCopyColumn(object obj) +{ + if (obj is TreeGridColumnContextMenuInfo) + { + // The selected column is stored into CopiedColumn. + CopiedColumn = (obj as TreeGridColumnContextMenuInfo).Column; + } +} + +private static void OnPasteColumn(object obj) +{ + if (obj is TreeGridColumnContextMenuInfo && CopiedColumn != null) + { + var grid = (obj as TreeGridColumnContextMenuInfo).TreeGrid; + // Get the index for corresponding column. + var index = grid.Columns.IndexOf((obj as TreeGridColumnContextMenuInfo).Column); + // Copy the column and insert based on the index position. + grid.Columns.Insert(index + 1, new TreeGridTextColumn() { MappingName = CopiedColumn.MappingName }); + } +} +``` + +### Copy the ID column using context menu + +![Copying the ID column using context menu](CopyingUsingContextMenu.png) + +### Paste the ID column after ReportsTo column + +![Pasting the ID column using context menu](PastingUsingContextMenu.png) \ No newline at end of file