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
close icon

Invalid ClipboardPaste generates unhandled error

Hi, I'm using a databound grid in a VB.Net project. I can paste cells from Excel to the grid when I select a range of cells that match the size and type of the cells copied to the clipboard. However, if I try to CTRL-C CTRL-V cells from Excel to the grid, I get an unhandled error if some cell values are incorrect. How can I trap the error gracefully (and cancel the paste and display an error message)? Also, I have some columns that contain dates that can't be modified. I'd like to validate if the dates being pasted matches the dates in the corresponding date column and cancel the paste if they differ. Third, is it possible to paste a range of rows : - by selecting a single cell? - by selecting a single row? - by selecting a range of cells or rows? - by selecting the whole grid? And how would I handle the different cases programmatically (or identify each case and cancel the paste and return an error message for some cases I decide not to handle). Any VB sample would be appreciated. Thanks Francois Rioux

4 Replies

AD Administrator Syncfusion Team August 13, 2003 08:40 PM UTC

Attached is a sample. It shows two ways to catch the paste error. One is to derive the grid, override OnKeyDown and catch the error there. The second option is to handle the grid.Model.ClipboardPaste event, and handl eteh entire paste yourself. This gives the greatest flexibility in handling the error. The ClipboardPaste event could also be used to handle your second question. You could test the exisitng value before setting the new value. I do not understand your last question. You do not have to seelct the exact range type before you paste. You could copy 3x6 cells in Excel, then click on a single cell and paste without having to select 3x6 cells. If you handle the ClipboardPaste, you can determine exactly the target range of cells anyway you want.


FR Francois Rioux August 14, 2003 10:38 AM UTC

Thanks for the sample. I'll use the clipboard paste option since I can perform my own integrity checks. I asked the last question because had played with a similar clipboardpaste sample a user provided in another thread. In both cases I get the same problem which led to my the last question that could circumvent the problem. If I paste a single value, into a single cell, it works fine, the error is raised (msgbox in your sample). The problem is when I paste a range of values into a range of cells. For what I can figure, the error is caught only if the cell in error is the initially current cell. Otherwise, the error is not caught and the paste does not occur for that cell.


FR Francois Rioux August 14, 2003 12:32 PM UTC

> Thanks for the sample. > > I'll use the clipboard paste option since I can perform my own integrity checks. > > I asked the last question because had played with a similar clipboardpaste sample a user provided in another thread. In both cases I get the same problem which led to my the last question that could circumvent the problem. > > If I paste a single value, into a single cell, it works fine, the error is raised (msgbox in your sample). > > The problem is when I paste a range of values into a range of cells. For what I can figure, the error is caught only if the cell in error is the initially current cell. Otherwise, the error is not caught and the paste does not occur for that cell. > To be more precise, when pasting in a range of cells, the error is not raised. For example in your sample form, you can copy 2 rows of the first two columns (String) and paste it over the Integer column and the following (string) column. Depending on the active cell (it seems to be the first cell when starting to select the range), the result will be different. If the active cell is in the integer column, the error is trapped in the code. Otherwise, the error is not raised and only the string cells are copied over. The integer cells keep their original value with apparently indication that something went wrong. Minimally, I would like to be able to tell the user that some cell could not be pasted as expected.


AD Administrator Syncfusion Team August 14, 2003 02:14 PM UTC

Instead of just setting the value in the grid, you can do your own validation in the Try Block.
Try
	If Me.GridDataBoundGrid1.Binder.InternalColumns(j0 + j).MappingName = "Integer" Then 'columnname
		Integer.Parse(s)
	End If
	Me.GridDataBoundGrid1(i0 + i, j0 + j).Text = s
Catch
	MessageBox.Show(String.Format("Paste-error {0},{1}", i0 + i, j0 + j + 1))
End Try

Loader.
Live Chat Icon For mobile
Up arrow icon