I am handling Model.ClipboardPaste in my GDBG. As currently implemented, a user can paste an incompatible value-type leading to System.Format exceptions (input string was not in correct format).
I noticed that the GDBC handles this exception when editing a cell by popping up a msg and disallowing the user to leave the cell until the format is cleared up.
I would like to have the paste operation also validate the value for each cell. For now, I would be happy enough simply rejecting the entire paste if there are any value-type mismatches anywhere in the cells being paste.
I thought about handling PasteCellText as well as trying to validate the values inside my ClipboardPaste handler. But the problem is complicated by not knowing what the column types will be in advance. So I cannot hard-code the validation rules.
I would even be happy enough to be able to trap any exceptions thrown by the paste operation. But I don''t know how to do that.
If you just want to catch exceptions in ClipboardPaste, you can use code similar to that below. But you would have more control if you did use PasteCellText. You could probably use grid[e.RowIndex, e.Style.CellValueType to decide how to test the value.
I am using code somewhat like your example to catch and report the exceptions.
I agree that it would be better to validate each cell myself, but I have bigger fish to fry and deadlines to meet - you know how it is.
Thanks for you excellent (as always) help.