2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Clipboard operationBy default, GridGroupingControl cannot be copied the whole cell values for NestedGrid, it can be achieved by manually setting the clipboard text based on our need using ClipboardCopy event. C# private void TableModel_ClipboardCopy(object sender, GridCutPasteEventArgs e) { this.CopySelectedRecords(false); e.Handled = true; } private void CopySelectedRecords(bool cut) { string s = ""; //Copying visible column names to the string buffer. foreach (GridVisibleColumnDescriptor cd in this.gridGroupingControl1.TableDescriptor.VisibleColumns) { int index = this.gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf(cd); if (index != 0) { s += "\t"; } s += cd.Name; } s += Environment.NewLine; //Copying the selected records. if (this.gridGroupingControl1.Table.SelectedRecords.Count > 0) { //Selection is made in the parent table foreach (SelectedRecord selRec in this.gridGroupingControl1.Table.SelectedRecords) { s = CopySelectedRecordsToBuffer(s, selRec.Record, gridGroupingControl1.TableDescriptor, cut); } } else { //Selection is made in the child table. s = ""; GridTable child = gridGroupingControl1.GetTable("MarkSheet"); if (child.SelectedRecords.Count > 0) { //Copying visible column names of the child table into the string buffer. foreach (GridVisibleColumnDescriptor cd in child.TableDescriptor.VisibleColumns) { int index = child.TableDescriptor.VisibleColumns.IndexOf(cd); if (index != 0) { s += "\t"; } s += cd.Name; } s += Environment.NewLine; foreach (SelectedRecord r in child.SelectedRecords) { s = CopySelectedRecordsToBuffer(s, r.Record, child.TableDescriptor, cut); } } } Clipboard.SetDataObject(new DataObject(s), true); }
VB Private Sub TableModel_ClipboardCopy(ByVal sender As Object, ByVal e As GridCutPasteEventArgs) Me.CopySelectedRecords(False) e.Handled = True End Sub Private Sub CopySelectedRecords(ByVal cut As Boolean) Dim s As String = "" 'Copying visible column names to the string buffer. For Each cd As GridVisibleColumnDescriptor In Me.gridGroupingControl1.TableDescriptor.VisibleColumns Dim index As Integer = Me.gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf(cd) If index <> 0 Then s &= Constants.vbTab End If s &= cd.Name Next cd s &= Environment.NewLine 'Copying the selected records. If Me.gridGroupingControl1.Table.SelectedRecords.Count > 0 Then 'Selection is made in the parent table For Each selRec As SelectedRecord In Me.gridGroupingControl1.Table.SelectedRecords s = CopySelectedRecordsToBuffer(s, selRec.Record, gridGroupingControl1.TableDescriptor, cut) Next selRec Else 'Selection is made in the child table. s = "" Dim child As GridTable = gridGroupingControl1.GetTable("MarkSheet") If child.SelectedRecords.Count > 0 Then 'Copying visible column names of the child table into the string buffer. For Each cd As GridVisibleColumnDescriptor In child.TableDescriptor.VisibleColumns Dim index As Integer = child.TableDescriptor.VisibleColumns.IndexOf(cd) If index <> 0 Then s &= Constants.vbTab End If s &= cd.Name Next cd s &= Environment.NewLine For Each r As SelectedRecord In child.SelectedRecords s = CopySelectedRecordsToBuffer(s, r.Record, child.TableDescriptor, cut) Next r End If End If Clipboard.SetDataObject(New DataObject(s), True) End Sub
Samples: C# : Pastetocell_CS VB : Pastetocell_VB Reference links: 1.https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/selections 2. https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/clipboard-operations |
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.