Skip to content

Commit d391f2d

Browse files
authored
Merge pull request #2 from SyncfusionExamples/ES-975464
ES-975464 - Resolve the ReadMe file length issue in this sample repository
2 parents 328298b + 8e44c3a commit d391f2d

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

CopyingUsingContextMenu.png

132 KB
Loading

PastingUsingContextMenu.png

114 KB
Loading

README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
1-
# How to copy a column and paste it as a new column in wpf treegrid?
2-
This sample illustrates how to copy a column and paste it as a new column in wpf treegrid
1+
# How to Copy a Column and Paste it as a New Column in WPF TreeGrid?
2+
3+
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).
4+
5+
You can copy a column and paste it into a new position using the context menu option in TreeGrid.
6+
7+
### XAML
8+
9+
``` xml
10+
<syncfusion:SfTreeGrid.HeaderContextMenu>
11+
<ContextMenu ItemsSource="{Binding Menu,Source={StaticResource viewmodel}}" >
12+
<ContextMenu.ItemContainerStyle>
13+
<Style TargetType="MenuItem">
14+
<Setter Property="Command" Value="{Binding MyCommand,Source={StaticResource viewmodel}}">
15+
</Setter>
16+
<Setter Property="CommandParameter" >
17+
<Setter.Value>
18+
<MultiBinding Converter="{StaticResource ResourceKey=converter}">
19+
<Binding RelativeSource="{RelativeSource Self}"/>
20+
<Binding />
21+
</MultiBinding>
22+
</Setter.Value>
23+
</Setter>
24+
</Style>
25+
</ContextMenu.ItemContainerStyle>
26+
</ContextMenu>
27+
</syncfusion:SfTreeGrid.HeaderContextMenu>
28+
```
29+
30+
### C#
31+
32+
``` c#
33+
private static void OnCopyColumn(object obj)
34+
{
35+
if (obj is TreeGridColumnContextMenuInfo)
36+
{
37+
// The selected column is stored into CopiedColumn.
38+
CopiedColumn = (obj as TreeGridColumnContextMenuInfo).Column;
39+
}
40+
}
41+
42+
private static void OnPasteColumn(object obj)
43+
{
44+
if (obj is TreeGridColumnContextMenuInfo && CopiedColumn != null)
45+
{
46+
var grid = (obj as TreeGridColumnContextMenuInfo).TreeGrid;
47+
// Get the index for corresponding column.
48+
var index = grid.Columns.IndexOf((obj as TreeGridColumnContextMenuInfo).Column);
49+
// Copy the column and insert based on the index position.
50+
grid.Columns.Insert(index + 1, new TreeGridTextColumn() { MappingName = CopiedColumn.MappingName });
51+
}
52+
}
53+
```
54+
55+
### Copy the ID column using context menu
56+
57+
![Copying the ID column using context menu](CopyingUsingContextMenu.png)
58+
59+
### Paste the ID column after ReportsTo column
60+
61+
![Pasting the ID column using context menu](PastingUsingContextMenu.png)

0 commit comments

Comments
 (0)