Category / Section
How to programmatically copy a selection to the clipboard in WinForms GridControl?
1 min read
Clipboard operation
You can copy the range of cells that are already selected in the Grid by using CutPaste.Copy() method.
C#
//To copy the selected range this.gridControl1.CutPaste.Copy();
VB
'To copy the selected range Me.gridControl1.CutPaste.Copy()
When you want to copy the cells that are not in the selection of the Grid, use the CutPaste.CopyCellsToClipboard or CutPaste.CopyTextToClipboard methods depending upon whether you want to copy the styles or only the text to the clipboard.
C#
//To copy a particular range GridRangeInfo gi = GridRangeInfo.Cells(2, 2, 4, 5); GridRangeInfoList list = new GridRangeInfoList(); list.Add(gi); this.gridControl1.CutPaste.CopyTextToClipboard(list);
VB
'To copy a particular range Dim gi As GridRangeInfo = GridRangeInfo.Cells(2, 2, 4, 5) Dim list As New GridRangeInfoList() list.Add(gi) Me.gridControl1.CutPaste.CopyTextToClipboard(list)
The following screenshot displays the Grid with CutPaste.CopyCellsToClipboard or CutPaste.CopyTextToClipboard methods.
Figure 1: Copy the selection to clipboard
Samples: