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

Copy / paste in GGC

Hi,
I try to perform a clipboard copy / paste operation in a GGC, for a single record. The copy seems to get in (let me know if there is any better), but it seems I can paste only the first cell. Here is the code I use for the copy:

Private Sub Model_ClipboardCanCopy(ByVal sender As Object, ByVal e As GridCutPasteEventArgs)

Dim RowIndex = GridGroupingControl1.Table.CurrentRecord.GetRowIndex

Dim str As String = Nothing

For Each descriptor As FieldDescriptor In Me.GridGroupingControl1.TableDescriptor.Fields

str &= Me.GridGroupingControl1.Table.Records(RowIndex).GetValue(descriptor).ToString() & Constants.vbTab

Next descriptor

Clipboard.SetText(str)

GridGroupingControl1.TableModel.CutPaste.Copy()

End Sub

Additionally, I would like to know if a paste can be performed in the AddNew row?

Thank you in advance!- Nicolas



6 Replies

MG Mohanraj Gunasekaran Syncfusion Team September 1, 2016 01:34 PM UTC

Hi Nicolas, 

Thanks for using Syncfusion products. 

Please find the response for your queries, 

I try to perform a clipboard copy / paste operation in a GGC, for a single record. The copy seems to get in (let me know if there is any better), but it seems I can paste only the first cell. 

Solution 1 
The reported scenario can be achieved by using Clipboard.SetDataObject method as of follows. Please refer the below mentioned code snippet. 
 
Code snippet: 
Private Sub TableModel_ClipboardCopy(ByVal sender As Object, ByVal e As GridCutPasteEventArgs) 
 
Dim rowindex As Integer = Me.gridGroupingControl1.Table.CurrentRecord.GetSourceIndex() 
copiedrecord = Me.gridGroupingControl1.Table.Records(rowindex) 
value = String.Empty 
For Each column As GridVisibleColumnDescriptor In Me.gridGroupingControl1.TableDescriptor.VisibleColumns 
                value += Me.gridGroupingControl1.Table.Records(rowindex).GetValue(column.Name).ToString() & Constants.vbTab 
Next column 
Clipboard.SetDataObject(New DataObject(value), True) 
End Sub 
 
Solution 2 
This can be achieved by using Record.GetValue and Record.SetValue method in ClipboardCopy and ClipboardPaste event. Please refer the below code snippet, 

Code snippet: 
Private copiedrecord As Record 
 
Private Sub TableModel_ClipboardCopy(ByVal sender As Object, ByVal e As GridCutPasteEventArgs) 
                Dim rowindex As Integer = Me.gridGroupingControl1.Table.CurrentRecord.GetSourceIndex() 
                copiedrecord = Me.gridGroupingControl1.Table.Records(rowindex) 
End Sub 
 
Private Sub TableModel_ClipboardPaste(ByVal sender As Object, ByVal e As GridCutPasteEventArgs) 
              e.Handled = true
                      For Each column As GridVisibleColumnDescriptor In Me.gridGroupingControl1.TableDescriptor.VisibleColumns 
                                Dim Copiedvalue As String = copiedrecord.GetValue(column.Name).ToString() 
                                Me.gridGroupingControl1.Table.CurrentRecord.SetValue(column.Name, Copiedvalue) 
                Next column 
End Sub 

 
Additionally, I would like to know if a paste can be performed in the AddNew row? 

Yes. You can paste the copied values in AddNew row also. Please refer the below attached sample. 

Sample link: DataGrid 

Regards, 
Mohanraj G 
 



NI Nicolas September 1, 2016 08:48 PM UTC

Hi Mohanraj, thank you for the code, it's working great, but apparently there is a small glitch with finding the appropriate row index on the COPY side.  Using GetSourceIndex, sometimes the record address is correct, some other times, it is not. Alternatively, I tried with GGC.Table.CurrentRecord.GetRowIndex and with GGC.TableControl.CurrentCell.RowIndex (Which are giving the same result, but different than using GetSourceIndex), but are still giving the wrong index address for some records.

Later on, I figured that the "shown" row order might have been affected by the sorting I made in my GGC (GGC.TableDescriptor.SortedColumns.add("MySortedColumn", ListSortDirection.Ascending). In "commenting" this line, the order of appearance has changed and the clipboard operation control-copy / control-paste is working perfectly for all records. Is it possible to arrange this small glitch? - Thank you in advance, Nicolas


NI Nicolas September 1, 2016 09:28 PM UTC

Hi Mohanraj, I was able to replicate the issue, please try copy the last record, and paste it in the AddNew. The only item I added is the sorting feature on the Load event. Please find attached the file (only the 2015 version has been modified)

Attachment: VB1797251573_461268a0.rar


MG Mohanraj Gunasekaran Syncfusion Team September 2, 2016 01:20 PM UTC

Hi Nicloas, 

Thanks for your update, 

In order to get the current record of the table, you can use the Table.CurrentRecord property or Table.GetInnerMostCurrentElement().GetRecord() method. Please refer the below code snippet and refer the attached sample.  
 
Code snippet: 
Private copiedrecord As Record 
copiedrecord = Me.gridGroupingControl1.Table.CurrentRecord 
                   (or) 
copiedrecord = Me.gridGroupingControl1.Table.GetInnerMostCurrentElement().GetRecord() 
 
Sample link: DataGrid 
 
Regards, 
Mohanraj G. 



NI Nicolas September 2, 2016 03:58 PM UTC

Hi Mohanraj, this does perfectly the job! Thank you for your kind support! - Nicolas


MG Mohanraj Gunasekaran Syncfusion Team September 5, 2016 04:36 AM UTC

Hi Nicolas, 

Thanks for your update, 

We are glad to know that your reported problem has been resolved. Please let us know if you need any further assistance. 

Regards, 
Mohanraj G. 


Loader.
Live Chat Icon For mobile
Up arrow icon