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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Validating data-type compatibility in paste handler

Thread ID:





23450 Jan 12,2005 07:20 PM UTC Jan 13,2005 11:24 AM UTC WinForms 2
Tags: GridControl
Administrator [Syncfusion]
Asked On January 12, 2005 07:20 PM UTC

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 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)
	this.inPaste = true;
		MessageBox.Show("Bad Paste");
		e.Handled = true;
		this.inPaste = false;

Administrator [Syncfusion]
Replied On 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


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon