)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to copy the data from one row to many rows and one column to many columns in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: February 15, 2016 |
Last Revised Date: January 2, 2020
Tags: copypaste

Clipboard operation

In order to copy the data from one row to many rows and one column to many columns, the ClipBoardCanPaste event can be used. The target row or column range has to be given based on the Row and Column cells pasting. The data can be pasted to grid by using PasteTextFromBuffer method.

C#

//To paste at all the selected columns
gridControl1.ClipboardCanPaste += new GridCutPasteEventHandler(gridControl1_ClipboardCanPaste);
private void gridControl1_ClipboardCanPaste(object sender, GridCutPasteEventArgs e)
{
//For copying the data from one column to many columns.
   if (this.gridControl1.Model.SelectedRanges.ActiveRange.IsCols)
   {
      for (int i = this.gridControl1.Model.SelectedRanges.ActiveRange.Left; i <= this.gridControl1.Model.SelectedRanges.ActiveRange.Right; i++)
      {
         GridRangeInfo range = GridRangeInfo.Cells(1, i, this.gridControl1.RowCount, i);
         IDataObject iData = Clipboard.GetDataObject();
         string buffer = iData.GetData(DataFormats.UnicodeText) as string;
          if (buffer != null)
          {  
             this.gridControl1.Model.TextDataExchange.PasteTextFromBuffer(buffer, range, GridDragDropFlags.Text);
          }
       }
   }
//For copying the data from one row to many rows.
   else if (this.gridControl1.Model.SelectedRanges.ActiveRange.IsRows)
   {
      for (int i = this.gridControl1.Model.SelectedRanges.ActiveRange.Top; i <= this.gridControl1.Model.SelectedRanges.ActiveRange.Bottom; i++)
      {
         GridRangeInfo range = GridRangeInfo.Cells(i, 1, i, this.gridControl1.ColCount);
         IDataObject iData = Clipboard.GetDataObject();
         string buffer = iData.GetData(DataFormats.UnicodeText) as string;
         if (buffer != null)
         {   
            this.gridControl1.Model.TextDataExchange.PasteTextFromBuffer(buffer, range, GridDragDropFlags.Text);
         }
      }
   }
}

 

VB

'To paste at all the selected columns
AddHandler gridControl1.ClipboardCanPaste, AddressOf gridControl1_ClipboardCanPaste
Private Sub gridControl1_ClipboardCanPaste(ByVal sender As Object, ByVal e As GridCutPasteEventArgs)
‘For copying the data from one column to many columns.
   If Me.gridControl1.Model.SelectedRanges.ActiveRange.IsCols Then
      For i As Integer = Me.gridControl1.Model.SelectedRanges.ActiveRange.Left To Me.gridControl1.Model.SelectedRanges.ActiveRange.Right
         Dim range As GridRangeInfo = GridRangeInfo.Cells(1, i, Me.gridControl1.RowCount, i)
         Dim iData As IDataObject = Clipboard.GetDataObject()
         Dim buffer As String = TryCast(iData.GetData(DataFormats.UnicodeText), String)
         If buffer IsNot Nothing Then
            Me.gridControl1.Model.TextDataExchange.PasteTextFromBuffer(buffer, range, GridDragDropFlags.Text)
         End If
      Next i
‘For copying the data from one row to many rows. 
   ElseIf Me.gridControl1.Model.SelectedRanges.ActiveRange.IsRows Then
      For i As Integer = Me.gridControl1.Model.SelectedRanges.ActiveRange.Top To  Me.gridControl1.Model.SelectedRanges.ActiveRange.Bottom
          Dim range As GridRangeInfo = GridRangeInfo.Cells(i, 1, i, Me.gridControl1.ColCount)
          Dim iData As IDataObject = Clipboard.GetDataObject()
          Dim buffer As String = TryCast(iData.GetData(DataFormats.UnicodeText), String)
          If buffer IsNot Nothing Then
             Me.gridControl1.Model.TextDataExchange.PasteTextFromBuffer(buffer, range, GridDragDropFlags.Text)
          End If
       Next i
    End If
End Sub

 

Screenshot

Column based copying

Copy the data based on columns

Row based copying

Copy the data based on rows

Samples:

C#: Copy and Paste_CS

VB: Copy and Paste_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
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
Live Chat Icon