How to programmatically copy whole records to clipboard

Hi all,

although I use the Record-Based Selection, data of a specific cell is always copied to clipboard when using the TableModel.CutPaste.Copy method. The specific cell is either the cell I have clicked on in order to select the record or the cell in the first column of the record if I clicked on the record header in order to select the record.

My principal goal is to transfer the data of all cells of one or multiple records to clipboard (with support of extended multi-record selection). But I have the impression that I have to get rid of selecting specific cells and rather select entire records at once. But how to avoid the selection of specific cells when selecting records?

The curious thing is that it works when I use Model-Based Selection. If I select one or more records by clicking on record headers all cell data is copied to clipboard. But there I face the unnecessary selection of specific cells even more as a click on a cell does not select the whole record. This is why I switched my focus to Record-Based Selection.

Thanks in advance
Ben

1 Reply

MG Mohanraj Gunasekaran Syncfusion Team August 31, 2018 01:34 PM UTC

Hi Ben, 
 
Thanks for using Syncfusion product. 
 
To avoid the specific cell/column values while copying the text, you could handle the ClipboardCanCopy event using Handled and Result property. Please refer the following code example and the sample, 
 
Code example 
this.gridGroupingControl1.TableModel.ClipboardCanCopy += TableModel_ClipboardCanCopy; 
 
private void TableModel_ClipboardCanCopy(object sender, GridCutPasteEventArgs e) 
{ 
    this.CopySelectedRecords(false); 
    e.Result = false; 
    e.Handled = true; 
} 
 
private void CopySelectedRecords(bool cut) 
{ 
    string s = "";             
 
    //Copying the selected records. 
    if (this.gridGroupingControl1.Table.SelectedRecords.Count > 0) 
    { 
        foreach (SelectedRecord selRec in this.gridGroupingControl1.Table.SelectedRecords) 
        { 
            for (int i = 0; i < this.gridGroupingControl1.TableDescriptor.VisibleColumns.Count; i++) 
            { 
                GridVisibleColumnDescriptor vcd = this.gridGroupingControl1.TableDescriptor.VisibleColumns[i]; 
                if (vcd.Name != "Country") // Here, Country column value has avoided to copy the data  in clipboard. 
                { 
                    if (i != 0) 
                    { 
                        s += "\t"; 
                    } 
                    s += selRec.Record.GetValue(vcd.Name).ToString(); 
                    if (cut) 
                    { 
                        selRec.Record.SetValue(vcd.Name, ""); 
                    } 
                } 
            } 
            s += Environment.NewLine; 
        } 
    } 
             
    Clipboard.SetDataObject(new DataObject(s), true); 
} 
 
 
 
Please refer the following KB reference link to copy the value to clipboard, 
 
Regards, 
Mohanraj G 


Loader.
Up arrow icon