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. Image for the cookie policy date

cell addresses in GridControl copy / past

Is there a way to implement copy & paste in a GridControl so that cell references are automatically updated. For example, if I am copying the contents of cell B2 (containing the formula: =B4+B5) to cell C2, the formula being copied would be updated during the copy to reflect the appropriate cell references (ie; after the copy, the contents of C2 would read: =C4+C5)? I have looked through the knowledge base but haven't found anything that seems to work.

4 Replies

NR Nirmal Raja Syncfusion Team May 31, 2010 06:14 AM UTC

Hi Jan,

Thank you for your interest in Syncfusion products.

The copy and paste of a formula cell can be enabled to paste with the reference of the cell as in the Excel, by retrieving the GridFormulaEngine of the corresponding cells, and specify the copy flag to ClipBoardReferencesAdjusted and InsDelRangeReferencesUpdated.

Please refer the code below:
GridFormulaEngine engine = ((GridFormulaCellModel)this.gridControl1.CellModels["FormulaCell"]).Engine;
engine.FormulaCopyFlags |= GridFormulaCopyFlags.InsDelRangeReferencesUpdated;
engine.FormulaCopyFlags |= GridFormulaCopyFlags.ClipBoardReferencesAdjusted;


Also I have attached the sample in the below location:
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=FormulaRef1934678298.zip

Let me know if you have any queries.

Regards,
Nirmal


AD Administrator Syncfusion Team May 31, 2010 12:07 PM UTC

Thank you for the suggestion. I tried using your idea, but must have done it wrong. I took your example and added two buttons. The first copied the formula to the clipboard using

private void copyBtn_Click(object sender, EventArgs e)
{
Clipboard.SetText(gridControl1[1, 3].Text);
}

The second copied the formula back to the grid using

private void pasteBtn_Click(object sender, EventArgs e)
{
gridControl1[2, 3].Text = Clipboard.GetText();
}

After the copy, the formula had been copied correctly, but had not been updated to reflect the proper cells. It still read

"=Sum(A1:B1)"

What I am trying to do is have the formula be updated to read

"=Sum(A2:B2)"

That way I would be summing the two cells on the second row where the original formula sums the two cells on the first row.

Did I forget a step? Or is there something I'm just not understanding?

Thank you for you help.

-Jan-


AD Administrator Syncfusion Team May 31, 2010 08:37 PM UTC

Ignore previous update. I just got it figured out. Thank you for the help. While your suggestion didn't seem to work, (I don't know why), it obviously got me looking in the right spots. Who can ask for more?

v/r
Jan


NR Nirmal Raja Syncfusion Team June 1, 2010 11:44 AM UTC

Hi Jan,

Instead of using the Clipboard methods to copy and pasting cells, you can use the default copy paste from the grid object. The grid can copy the value directly from one cell and paste it to other with the help of CutPaste object.

Please refer the code below:
private void buttonAdv1_Click(object sender, EventArgs e)
{
gridControl1.CutPaste.CopyRange(GridRangeInfo.Cell(1, 3));
}

private void buttonAdv2_Click(object sender, EventArgs e)
{
gridControl1.CurrentCell.MoveTo(2, 3);
gridControl1.CutPaste.Paste();
}


Also please refer the sample below:
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=FormulaRef-126027284.zip

If you see any issue as pasting the cell on invisible range, it is a known issue and fixed in the latest source and will be available in the upcoming release. Let me know what kind of query you need with regards to the issue, and we will update you with the proper solution with regards to your request.

Let me know if you have any concern.

Regards,
Nirmal

Loader.
Live Chat Icon For mobile
Up arrow icon