How to abort pasting in GDBG?

Hello,

how can I abort clipboard pasting if content is bigger than GridDataBoundGrid row and column count?

Currently, I am using Model.PasteCellText event from next example: http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=327. Manual (http://www2.syncfusion.com/cref/Default.aspx##Class%20Reference.chm//E_Syncfusion_Windows_Forms_Grid_GridModel_PasteCellText.html) says that "e.Abort = true" abort current operation, but actually it does not rollback any changes, just stop the paste operation.

2 Replies

VA Valerij August 30, 2007 06:59 AM UTC

Here is little example.

0) Open&Run attached example
1) Select first 5 rows
2) Press ctrl + c
3) Move cursor to the next row (row "6")
4) Press ctrl + v

Error message appears, but rows 6-8 contains new values. How can I abort (rollback) pasting operation at all in case of error?


There also is strange difference in grid behaviour:

1) Open my example
2) Comment next line:
gridDataBoundGrid1.Model.PasteCellText += new Syncfusion.Windows.Forms.Grid.GridPasteCellTextEventHandler(Model_PasteCellText);
3) Run example
4) Select first 5 rows
5) Press ctrl + c
6) Move cursor to the next row (row "6")
7) Press ctrl + v

Ok. Now restart application

1) Select first 5 rows
2) Press ctrl + c
3) Now select rows from 6 to 8
4) Press ctrl + v

Exception is trown.

Why in first case exception is NOT thrown and in second case exception is thrown?

gridPaste_bug.zip


GR Golda Rebecal Syncfusion Team September 1, 2007 09:01 AM UTC

Hi Valerij,

Issue 1:

You can use ClipBoardPaste event to cancel pasting if the content to be pasted exceeds the grid row count.

void Model_ClipboardPaste(object sender, Syncfusion.Windows.Forms.Grid.GridCutPasteEventArgs e)
{
DataObject data = (DataObject)Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.Text))
{
ArrayList arr = new ArrayList();
string s = (string)data.GetData(DataFormats.Text);
string[] rows = s.Split(new char[] { '\n' });
int numRows = rows.GetLength(0);
if (numRows > 0 && rows[numRows - 1].Length == 0)
numRows--; //remove extra empty row if present

int rem = this.gridDataBoundGrid1.Model.RowCount - numRows;
if (rem < numRows)
{
e.Handled = true;
e.Result = true;
}
}
}

Please refer to the attached sample that illustrates the same:
http://websamples.syncfusion.com/samples/Grid.Windows/F67749/main.htm

Issue 2:
Exceptions occur in both the cases. In the first case, since the 6th row is in edit mode, EndEdit event is handled and then the ClipBoardPaste event is handled. In this case, you could see the exception message in the output window.

In the second case, since a range of rows is selected, ClipBoardPaste event is directly handled and exception is thrown explicitly.

Kindly let me know if you need any further assistance.

Best regards,
Golda

Loader.
Up arrow icon