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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to handle Copy and Paste of Read Only GridTreeControl?

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.

Figure 1: Row to Copy

The following screenshot displays the 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.

Sample Link: CopyandPasteDemo_GridTreeControl

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework: Product Version:
4056 02/17/2015 07/10/2015 WPF GridTreeControl 4.5 12.3.0.36
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon