Articles in this section
Category / Section

How to use Copy and Paste of Read Only GridTreeControl?

2 mins read

The GridTreeControl provides support for the clipboard copy and paste operations and not for ReadOnly Grid and columns. You can achieve this by changing the read only value of the Grid and Gridcell for the readonly column at runtime by using the ClipBoardPaste and ClipBoardPasted events in the GridTreeControl.

Refer to the following code example to wire the ClipboardPaste and ClipboardPasted events in the GridTreeControl.

C#

treeGrid.Model.ClipboardPaste += Model_ClipboardPaste;
treeGrid.Model.ClipboardPasted += Model_ClipboardPasted;

 

You need to set ReadOnly as false for both Grid and Gridcell to allow the paste operation in the ClipBoardPaste event when the Grid and Gridcell have ReadOnly as true. Please refer to the following code example that illustrates this.

C#

void Model_ClipboardPaste(object sender, GridCutPasteEventArgs e)
{
//Get and check the Row index by using RangeList.
      for (int row = e.RangeList.ActiveRange.Top; row <= e.RangeList.ActiveRange.Bottom; row++)
      {
//Check the condition based on the total column count.
         for (int col = 0; col < treeGrid.Model.ColumnCount; col++)
          {
//Get the column index by using ResolveIndexToColumnIndex.
              var colindex = treeGrid.Model.TreeGrid.ResolveIndexToColumnIndex(col);
//Check if the column as ReadOnly.
              if (colindex >= 0 && treeGrid.Columns[colindex].StyleInfo.ReadOnly)
               {
//Set ReadOnly as false for a GridCell.
                    treeGrid.Model[row, col].ReadOnly = false;
               }
            }
        }
//Set ReadOnly as false for Grid.
            treeGrid.ReadOnly = false;
    }

The ClipboardPasted event fires after pasting the data in the GridTreeControl and you can set an actual value, True, to ReadOnly property of the Grid and GridCell. Refer to the following code example that illustrates this.

C#

void Model_ClipboardPasted(object sender, GridCutPasteEventArgs e)
{
    //Get and check the Row index by using RangeList.
    for (int row = e.RangeList.ActiveRange.Top; row <= e.RangeList.ActiveRange.Bottom; row++)
      {
//Check the condition based on the total column count
            for (int col = 0; col < treeGrid.Model.ColumnCount; col++)
            {
 //Get the column index by using ResolveIndexToColumnIndex
                var colindex = treeGrid.Model.TreeGrid.ResolveIndexToColumnIndex(col);
//Check if the column as ReadOnly
                if (colindex >= 0 && !treeGrid.Columns[colindex].StyleInfo.ReadOnly)
                {
  //Set ReadOnly as true for GridCell
                      treeGrid.Model[row, col].ReadOnly = true;
                }
             }
        }
//Set ReadOnly as True for Grid
       treeGrid.ReadOnly = true;
}

The following screenshot displays the row to be pasted.

Row to Copy

Figure 1: Row to Copy

The following screenshot displays the row pasted.

Row pasted

 

Figure 2: The copied Row pasted

You can refer to the following sample link to handle the copy and paste operations for the ReadOnly Grid and columns.


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied