When pasting a range of cells in my Data Bound Grid it is possible to run into an error on one of the cells, such as the error "Input string was not in the correct format". Currently when this happens the cells that were pasted in this operation up to this point will stay put, but any further cells in the range will not attempt to paste. Additionally, when this happens, the Model.ClipboardPasted event doesn''t get fired, an event in which I am doing some important post-paste operations.
I would like to find a way to either cancel the entire paste operation when these errors are raised, or at least finish the operation for the remainder of the valid cells and ensure that the ClipboardPasted event fires upon completion. Any suggestions?
ADAdministrator Syncfusion Team March 3, 2005 02:04 PM
Try handling the PasteCelltext event. This is raised cell by cell as the text is being pasted. You can validate the text before grid tries to do the past on that cell. You have the option of canceling the single cell paste or cancelly the rest of the paste as well.
JLJeff LancasterMarch 3, 2005 02:49 PM
Thanks, Clay. Is there an easy way in this event to compare the text to the style and just cancel the cell paste if it won''t work? Or do I need to write my own set of validation rules for each column in the grid? I can certainly do this but I have a lot of columns so it will take quite a bit of code. If there''s a way to just "pre-try" the paste for each cell and catch the errors when they occur, that would be much simpler.
ADAdministrator Syncfusion Team March 3, 2005 03:02 PM
You could try code like this. It actually handles setting the values in the paste.
private void Model_PasteCellText(object sender, GridPasteCellTextEventArgs e)
this.gridDataBoundGrid1[e.RowIndex, e.ColIndex].Text = e.Text;
e.Cancel = true; //cancel it as you did the paste
//don''t show the message
this.gridDataBoundGrid1.CurrentCell.ErrorMessage = "";
e.Cancel = true; //as it cannot be done
//e.Abort = true;//if you want to stop pasting rest of cells