JJ
Jisha Joy
Syncfusion Team
October 15, 2008 06:45 AM UTC
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
MP
Markus Persson
October 15, 2008 08:34 AM UTC
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
MP
Markus Persson
October 15, 2008 09:12 AM UTC
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.
MP
Markus Persson
October 15, 2008 10:13 AM UTC
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)
MP
Markus Persson
October 17, 2008 02:38 PM UTC
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?
JJ
Jisha Joy
Syncfusion Team
October 24, 2008 05:31 AM UTC
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
MP
Markus Persson
October 24, 2008 07:20 AM UTC
Hello Jisha.
It works like a charm. :) Thank you for all your help!
SU
Santosh U
October 23, 2009 04:26 PM UTC
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
SU
Santosh U
November 3, 2009 12:59 PM UTC
Hi..
Anyone.... any update ???
Thanks,
Santosh
SU
Santosh U
November 14, 2009 06:05 AM UTC
Hi,
If someone has solution then please mention otherwise atleast mention that you do not have solution !!
Regards,
Santosh U