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. Image for the cookie policy date

Validating data-type compatibility in paste handler

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. Ideas? Thanks, Andy.

2 Replies

AD Administrator Syncfusion Team January 12, 2005 10:27 PM UTC

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.
bool inPaste = false;
private void Model_ClipboardPaste(object sender, GridCutPasteEventArgs e)
{
	if(this.inPaste)
		return;
	this.inPaste = true;
	try
	{
		if(this.gridDataBoundGrid1.CurrentCell.IsEditing)
			this.gridDataBoundGrid1.CurrentCell.EndEdit();
		this.gridDataBoundGrid1.Model.CutPaste.Paste();
	}
	catch
	{
		MessageBox.Show("Bad Paste");
	}
	finally
	{
		e.Handled = true;
		this.inPaste = false;
	}
}


AD Administrator Syncfusion Team January 13, 2005 11:24 AM UTC

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. Andy

Loader.
Up arrow icon