Cut-Copy-Paste Demo

This sample allows you to perform cut, copy, and paste operations with an hierarchical Grid Grouping Control.

Cut-Copy-Paste

CutCopyPasteSample

Features

The Grid Grouping Control in the sample is bound to a hierarchical data set comprising of two tables. A context menu is associated with the grouping grid to enable the required clipboard operations.

Implementation

This implementation contains a user-defined method, named CopySelectedRecords, to transfer the content of selected records from the grid grouping control to the clipboard. At first, it retrieves visible column names, which in turn are copied into a string buffer. For every record present in the Table.SelectedRecords collection, this method retrieves the value of the record, saves the value into the string buffer, and then checks for any nested tables associated with that record. If any such nested table exists, then it copies the values of all the records in the nested table into the string buffer. Finally, the content of the string buffer is written into the system clipboard via the Clipboard.SetDataObject method. 

 

      
      private void CopySelectedRecords(bool cut)
        {
            //other codes
            if (this.gridGroupingControl1.Table.SelectedRecords.Count > 0)
            {
                foreach (SelectedRecord selRec in this.gridGroupingControl1.Table.SelectedRecords)
                    s = CopySelectedRecordsToBuffer(s, selRec.Record, gridGroupingControl1.TableDescriptor, cut);
            }
            Clipboard.SetDataObject(new DataObject(s), true);
        }