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.
Unfortunately, activation email could not send to your email. Please try again.

Validating data-type compatibility in paste handler

Thread ID:

Created:

Updated:

Platform:

Replies:

23450 Jan 12,2005 02:20 PM Jan 13,2005 06:24 AM Windows Forms 2
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On January 12, 2005 02:20 PM

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.

Administrator [Syncfusion]
Replied On January 12, 2005 05:27 PM

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;
	}
}

Administrator [Syncfusion]
Replied On January 13, 2005 06:24 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;