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.

Cell copy/paste like Excel?

Thread ID:

Created:

Updated:

Platform:

Replies:

77090 Oct 13,2008 10:36 AM Nov 14,2009 01:05 AM Windows Forms 10
loading
Tags: GridControl
Markus Persson
Asked On October 13, 2008 10:36 AM

If you copy (Ctrl+C) a cell in Excel, and then select a bunch of cells and do a paste (Ctrl+V), you get all cells filled with what you had copied.

Does a feature like this exist in Syncfusion? And if so, how do I activate it?

Thanks.


Jisha Joy [Syncfusion]
Replied On October 15, 2008 02:45 AM


Hi Markus,

The desired behaviour can be achieved by handleing the ClipboardPaste paste event. Please refer the code:

this.gridControl1.Model.ClipboardPaste += new Syncfusion.Windows.Forms.Grid.GridCutPasteEventHandler(Model_ClipboardPaste);



void Model_ClipboardPaste(object sender, Syncfusion.Windows.Forms.Grid.GridCutPasteEventArgs e)
{

IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(typeof(string)))
{
string s = (string)data.GetData(typeof(string));
GridRangeInfoList rangeList;
if (this.gridControl1.Selections.GetSelectedRanges(out rangeList, true))
{
this.gridControl1.Model.ChangeCells(rangeList.ActiveRange, s);
e.Result = true;
e.Handled = true;
}
}

}

Please let me know if this helps.

Regards,
Jisha


Markus Persson
Replied On October 15, 2008 04:34 AM

Hi Jisha, it works like a charm, thanks!

Here's my modified VB-version of your code that I use:


Private Sub GridControl_ClipboardPaste(ByVal sender As System.Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCutPasteEventArgs) Handles gridControl1.ClipboardPaste
Dim data As IDataObject = Clipboard.GetDataObject()

If data.GetDataPresent(DataFormats.StringFormat) Then
Dim s As String = data.GetData(DataFormats.StringFormat)
Dim rangeList As GridRangeInfoList = Nothing

If sender.Selections.GetSelectedRanges(rangeList, True) Then
sender.Model.ChangeCells(rangeList.ActiveRange, s)
e.Result = True
e.Handled = True
End If
End If
End Sub


Markus Persson
Replied On October 15, 2008 05:12 AM

Some more follow-up questions.

If I only use my mouse and select an area and paste, it works just fine.
However, if I hold down Ctrl to just select a few cells, like A1, B3, D7 and then do a paste, it will only paste on the last selected cell (in this example, D7). Any ideas how to fix this?

And another question. I change the interior to another color when a user edit a cell so the user knows that he/she has some unsaved information on this grid. I did this by handling the CurrentCellEditingComplete action. However, it seems ClipboardPaste doesn't trigger this action, any ideas on how to solve this aswell?


Thanks.


Markus Persson
Replied On October 15, 2008 06:13 AM

I solved my second question, this is how I did it if someone else is interested (VB):


Find this line:
sender.Model.ChangeCells(rangeList.ActiveRange, s)

And replace it with:
Dim gsi As GridStyleInfo = New GridStyleInfo()
gsi.Interior = New Syncfusion.Drawing.BrushInfo(Color.CornflowerBlue)
gsi.Text = s
sender.Model.ChangeCells(rangeList.ActiveRange, gsi)


Markus Persson
Replied On October 17, 2008 10:38 AM

Someone who has an answer to my first question?
I'm using Syncfusion 6.4.0.14


>If I only use my mouse and select an area and paste, it works just fine.
However, if I hold down Ctrl to just select a few cells, like A1, B3, D7 and then do a paste, it will only paste on the last selected cell (in this example, D7). Any ideas how to fix this?


Jisha Joy [Syncfusion]
Replied On October 24, 2008 01:31 AM

Hi Markus,

My apologies for the delayed response.

Thie issue mentioned here can be solved by using the following modified code:


void Model_ClipboardPaste(object sender, Syncfusion.Windows.Forms.Grid.GridCutPasteEventArgs e)
{
this.gridControl1.CurrentCell.EndEdit();
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(typeof(string)))
{
string s = (string)data.GetData(typeof(string));
GridRangeInfoList rangeList;
if (this.gridControl1.Selections.GetSelectedRanges(out rangeList, true))
{
foreach (GridRangeInfo range in rangeList)
{

this.gridControl1.Model.ChangeCells(range, s);
}
e.Result = true;
e.Handled = true;
}
}
}

Let me know if this helps you out.

Regards,
Jisha


Markus Persson
Replied On October 24, 2008 03:20 AM

Hello Jisha.

It works like a charm. :) Thank you for all your help!


Santosh U
Replied On October 23, 2009 12:26 PM

Hi Jisha,

I have modified your example for GridGroupingControl like following

ggc.Table.CurrentRecord.EndEdit();
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(typeof(string)))
{
string s = (string)data.GetData(typeof(string));
GridRangeInfoList rangeList;
if (ggc.TableModel.Selections.GetSelectedRanges(out rangeList, true))
{
foreach (GridRangeInfo range in rangeList)
{
this.ggc.TableModel.ChangeCells(range, s);
}
e.Result = true;
e.Handled = true;
}
}

Everything works fine untill i call the method ChangeCells. I get an Error AddNew not called.

Here I do not have range selected. I just have one AddNewRecord field where I am pasting this.

How can we achieve such scenario. Multiple row copy and paste on empty ggc (with only one row of AddNewRecord.

Please help,

Thanks,
Santosh U

Santosh U
Replied On November 3, 2009 07:59 AM

Hi..

Anyone.... any update ???


Thanks,
Santosh

Santosh U
Replied On November 14, 2009 01:05 AM

Hi,

If someone has solution then please mention otherwise atleast mention that you do not have solution !!

Regards,
Santosh U

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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.

;