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
Syncfusion site will be temporarily unavailable for scheduled maintenance on December 14, 2024, from 10:30 PM ET to 11:30 PM ET.
close icon

Copy & Paste of Row

How to do Copy & Paste of Row(s)? Sample? Thanks Satish

26 Replies

AD Administrator Syncfusion Team July 6, 2004 08:51 AM UTC

By default, the grid should respond to ctl+C and ctl+V to copy and paste any selections, including selected rows. If you want to programatically copy and paste, you can call these methods. this.gridDataBoundGrid1.Model.CutPaste.Copy this.gridDataBoundGrid1.Model.CutPaste.Paste


CM Christian Morand July 6, 2004 02:05 PM UTC

How to do Copy & Paste of Row with ComboBox that contains ValueMember <> DisplayMember?


AD Administrator Syncfusion Team July 6, 2004 05:02 PM UTC

Copying and pasting to and from a GridControl, this would work by default as the styles themselves are copied and pasted there. But in a GridDataBoundGrid, only text is copied. So, in that grid, you would have to do things yourself. You can handle the grid.Model.ClipboardCopy event and do things there yourself. Here is a little sample. CopyPasteDisplayMember_833.zip


SA Satish July 7, 2004 03:22 AM UTC

How Can we do extended Cell copy and paste? This does n''t work for extended Cell it works for only the Active Cell. Thanks Satish >Copying and pasting to and from a GridControl, this would work by default as the styles themselves are copied and pasted there. But in a GridDataBoundGrid, only text is copied. So, in that grid, you would have to do things yourself. > >You can handle the grid.Model.ClipboardCopy event and do things there yourself. Here is a little sample. > >CopyPasteDisplayMember_833.zip > >


AD Administrator Syncfusion Team July 7, 2004 06:01 AM UTC

The reason the code in the sample does not handle a single cell is that it explicitly excludes this possibility with an If condition at the start of ClipboardCopy event handler code. If you want the same code to handle a single cell, then you could insert this code at the very top of that method to make sure there is a single selected cell when there are no other selections.
if(this.gridDataBoundGrid1.Selections.Ranges.ActiveRange.IsEmpty)
{		this.gridDataBoundGrid1.CurrentCell.EndEdit();
	this.gridDataBoundGrid1.Selections.Add(this.gridDataBoundGrid1.CurrentCell.RangeInfo);
}


SA Satish July 7, 2004 07:00 AM UTC

Clay, Thanks for reply. But my requirement is if user can select Column 1 Row 2,Column 5 Row 2, Column 3 Row 4 and copy and paste. How do we handle in this case? Thanks Satish >The reason the code in the sample does not handle a single cell is that it explicitly excludes this possibility with an If condition at the start of ClipboardCopy event handler code. > >If you want the same code to handle a single cell, then you could insert this code at the very top of that method to make sure there is a single selected cell when there are no other selections. > >
>if(this.gridDataBoundGrid1.Selections.Ranges.ActiveRange.IsEmpty)
>{		this.gridDataBoundGrid1.CurrentCell.EndEdit();
>	this.gridDataBoundGrid1.Selections.Add(this.gridDataBoundGrid1.CurrentCell.RangeInfo);
>}
>


AD Administrator Syncfusion Team July 7, 2004 07:23 AM UTC

The code posted works for only the active range in grid.Selections.Ranges. If you want to handle every range in grid.Selections.Ranges, then you would loop through grid.Selections.Ranges, and apply the sample code to every range in the collection. The object being put on the clipboard would just be a tab delimited string. It would be one block holding all the data from the multiple selections. So, when you paste it, the paste area would be contiguous, unlike the cells that were copied. If you do not want this, then you would have to create a custom data object that, in addition to storing the data, also stored something to reflect the position of the data. Then your paste target would have to be able to handle this special data object and paste it appropriately. For example, Excel could not accept this custom object for pasting as it would not be one of the formats that Excel would understand.


SA Satish July 9, 2004 05:51 AM UTC

Hi I have written code for Blank (Cell/Row/Extended Selected/Table). Anything needs to be changed out here Clay. Thanks Satish private int GetColumnNumber(string rowName) { string k="0"; bool foundCol=false; for (int i=0;iThe code posted works for only the active range in grid.Selections.Ranges. If you want to handle every range in grid.Selections.Ranges, then you would loop through grid.Selections.Ranges, and apply the sample code to every range in the collection. The object being put on the clipboard would just be a tab delimited string. It would be one block holding all the data from the multiple selections. So, when you paste it, the paste area would be contiguous, unlike the cells that were copied. If you do not want this, then you would have to create a custom data object that, in addition to storing the data, also stored something to reflect the position of the data. Then your paste target would have to be able to handle this special data object and paste it appropriately. For example, Excel could not accept this custom object for pasting as it would not be one of the formats that Excel would understand. > >


AD Administrator Syncfusion Team July 9, 2004 06:31 AM UTC

I don''t know what might changes might be needed. What doesn''t work?


MP Markus Persson May 14, 2009 03:30 PM UTC

Hello Clay, can you upload that sample again since it doesn't seem to exist on this new page of Syncfusion? That example seems to be exactly what I'm looking for so I would really appreciate it. Thanks.


RC Rajadurai C Syncfusion Team May 18, 2009 12:53 PM UTC

Hi Markus,

Thanks for your interest in Syncfusion products.

Please refer to the following link which holds the sample in the mentioned link 'CopyPasteDisplayMember_833.zip'.
http://files.syncfusion.com/support/samples/Grid.Windows/7.2.0.20/F16088.zip

Regards,
Rajadurai


MP Markus Persson May 20, 2009 12:44 PM UTC

Thanks, but unfortunately it wasn't the answer for my problem that I was hoping for.


I'm using a GridControl and I wonder how do I paste multiple of cells with ComboBox that contains ValueMember not equal to DisplayMember?

Copy & Paste one cell at a time works fine. But if I copy a combobox-cell, and select a bunch of combobox-cells and paste so is it only the active cell that get the paste. I want all the selected cells to get the paste. How do I achieve this?


LS Lingaraj S Syncfusion Team May 23, 2009 06:57 AM UTC

Hi Markus,

Thank you for your update.

Please refer the sample, shipped along with our product in below location.
Grid Samples -> MS Excel- Style Features -> Grid Copy-Paste Demo

This sample demonstrate how to copy and paste the cells with formatting in GridControl.

Please let me know if it helps.

Regards,
Lingaraj S.


MP Markus Persson May 25, 2009 09:25 AM UTC

It doesn't help, it has the exact same problem.

Try it yourself, select one cell, copy it. Select a bunch of cells (say 3x3 cells), and paste. You will find that you only have pasted into one cell (the active one), and not nine. I want all nine cells (the selected 3x3 cells) to get the paste.

And I want to achieve this with combobox-cells.


LS Lingaraj S Syncfusion Team May 27, 2009 05:15 PM UTC

Hi Markus,

Thank you for your update.

I am unble to see the issue in copy the multiple combobox cell in GridControl. I have tried with multiple ComboBox, the combobox values are correctly pasted into the GridControl. Also I have attched the video file which I tried with previous mentioned location sample.
http://files.syncfusion.com/support/samples/Grid.Windows/Forums/CopyPaste.zip

Please let me know if you still face the issue, it would be be helpful to more details on the issue.

Regards,
Lingaraj S.


MP Markus Persson May 28, 2009 09:33 AM UTC

Hello Lingaraj.

Thanks for helping me out, but you are doing it the other way around.
1. You are selecting a bunch of ComboBox cells. Not one.
2. You are pasting into one cell, not many.


I have created a simple solution (VS 2008, VB.Net) that contains my problem.
1. Run my example
2. Select cell 1A, and select the value 'Three'
3. Now, copy this cell (1A), and this cell only!
4. Select a bunch of other cells, let's say 3A to 7A (that should be five cells in your selection).
5. Paste.
6. Result is that only the active cell get the paste, and not all five selected cells. I want all selected cells to get this paste.



SF_GridControl_ComboBox_CopyPaste_f7dc1704.zip


LS Lingaraj S Syncfusion Team June 8, 2009 08:57 PM UTC

Hi Markus,

Thank you for the update.

If you want to paste a single cell value into multiple selected cell, it can be achieved through by workaround in GridControl. The ClipboardCanPaste event is fired, when the Paste operation has been performed in GridControl. So please try using the ClipboardCanPaste event in GridControl to achieve this behavior. The Clipboard object used in ClipboardCanPaste event to retrieve the copied value and set into GridControl cell.

Please refer the modified sample in below link:
http://files.syncfusion.com/support/samples/Grid.Windows/Forums/SFGridModified.zip

Let me know if you have any queries.

Regards,
Lingaraj S.


MP Markus Persson June 9, 2009 12:21 PM UTC

Thanks for trying Lingaraj, but there are still some errors.

You are only copying the text, for example "Two", to the other comboboxes. Of course the valuemember (2) needs to be copied as well!

I have updated the example so it will display an error so you can see. First, try just to run it and copy one combobox at a time, and you will see it works. Then uncomment line 47 ('AddHandler GridControl1.Model.ClipboardCanPaste, AddressOf Model_ClipboardCanPaste) so your ClipboardCanPaste-event works, and try again. You will notice that you can't paste anything anymore since you only are trying to copy the displaymember.

How to fix this?



SFGridModified_71227c4f.zip


RC Rajadurai C Syncfusion Team June 10, 2009 01:18 PM UTC

Hi Markus,

Please try the following modified code in Model_ClipboardCanPaste method as this solves the issue while pasting multiple cells.

Private Sub Model_ClipboardCanPaste(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCutPasteEventArgs)
Dim dataObject As IDataObject = Clipboard.GetDataObject()
If dataObject IsNot Nothing Then
Dim s As String = CType(dataObject.GetData(DataFormats.Text), String)
Dim copran As GridRangeInfo = Me.GridControl1.Selections.Ranges.ActiveRange
For i As Integer = copran.Top To copran.Bottom
For j As Integer = copran.Left To copran.Right
Me.GridControl1.Model(i, j).FormattedText = s
Next j
Next i
End If
e.Handled = True
e.Result = False
End Sub


Regards,
Rajadurai


MP Markus Persson June 10, 2009 02:25 PM UTC

Thanks Rajadurai, this seems like what I was looking for!

However, I modified it a bit so it can handle more selections aswell (incase the user select multiple cells with the CTRL-button). Here's my slightly modified code for this, if anyone in the future is looking for a solution like this.


Private Sub Model_ClipboardCanPaste(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCutPasteEventArgs)
Dim dataObject As IDataObject = Clipboard.GetDataObject()

If dataObject IsNot Nothing Then
Dim s As String = CType(dataObject.GetData(DataFormats.Text), String)

For Each copran As GridRangeInfo In Me.GridControl1.Selections.Ranges
For i As Integer = copran.Top To copran.Bottom
For j As Integer = copran.Left To copran.Right
Me.GridControl1.Model(i, j).FormattedText = s
Next j
Next i
Next
End If

e.Handled = True
e.Result = False
End Sub


Thank you all in Syncfusion for helping me out with this!


BE Bilal Esmael September 24, 2009 01:57 PM UTC

Hello,

If we write some code in ClipboardPaste event, this code will be executed before paste the content of the clipboard.

Is there any way (or event) to execute this code AFTER the paste?!

Regards,
Bilal


LS Lingaraj S Syncfusion Team September 25, 2009 02:07 PM UTC

Hi Bilal,

Thank you for your interest in Syncfusion products.

If you want to execute your own codes after execution of ClipboardCanPaste event, it can be achieved by using the conditional statements in GridControl events.

Refer the code below:

this.gridControl1.Model.ClipboardCanPaste += new GridCutPasteEventHandler(Model_ClipboardCanPaste);
// It is used to capture after paste for single cell
this.gridControl1.Model.CellsChanged += new GridCellsChangedEventHandler(Model_CellsChanged);
// It is used to capture after paste for Multiple cell
this.gridControl1.CurrentCellChanged += new EventHandler(gridControl1_CurrentCellChanged);
bool pasted = false;
void Model_ClipboardCanPaste(object sender, GridCutPasteEventArgs e)
{
// To intimate the paste operation
pasted = true;
}
void gridControl1_CurrentCellChanged(object sender, EventArgs e)
{
if (pasted)
{
pasted = false;
MessageBox.Show("Pasted");
}
}
void Model_CellsChanged(object sender, GridCellsChangedEventArgs e)
{
if (pasted)
{
pasted = false;
MessageBox.Show("Pasted");
}
}


Refer the sample from below link:
http://files.syncfusion.com/support/samples/Grid.Windows/7.3.0.20/Forums/GridAfterPaste.zip

Please let me know if you have any queries.

Regards,
Lingaraj S.


AB Adam Bruss July 11, 2016 04:40 PM UTC

When I paste cells into my gridcontrol it creates new rows. For example if I copied two cells on top of each other and then pasted into the bottom cell of the grid it adds one new row. I don't want it to add rows. How can I prevent new rows from being added?


VS Venkatesh Sundaram Syncfusion Team July 12, 2016 10:35 AM UTC

Hi Adam,  
Thank you for the update.  
If you want to avoid the unwanted rows/columns to be appended to the GridControl, set the ClipboardFlags. Please refer to the following code example in that code is used to avoid the adding of rows and columns.     
this.gridControl1.CutPaste.ClipboardFlags |= GridDragDropFlags.NoAppendRows;    
Refer to the link below for more information about Copy and Paste.    
 
Regards,  
Venkat. 



AB Adam Bruss July 12, 2016 02:36 PM UTC

Thanks, that worked well.


VS Venkatesh Sundaram Syncfusion Team July 13, 2016 05:54 AM UTC

Hi Adam, 
 
Thanks for the update. Please let us know if you need any further assistance. 
 
Regards, 
Venkat. 


Loader.
Up arrow icon