I ran in to this casting error today and I cant seem to figure out whats going on with it. Run my sample and put in 100.00 in cell 1,1 and then hit Ctrl-c. Next click the header cell in col2 so it highlights the whole col and push ctrl-v. it will paste the 100 in to cell 1,2. we are working on one to many copying and this is where i caught it. Now while col2 is still selected you hold down your shift key and hit the right arrow key like 4 or 5 times in a row you blow up with a cast error. Its trying to do something with the text in the header cell for col2 and i cant figure out why. it doesnt do it if you use ur mouse to arrow over the cols to select them. its blowing up in the current cell validating event and i dont even know why its going there. Am I missing something. It doesnt look like it attached the file so i will email it also.
ADAdministrator Syncfusion Team April 11, 2005 03:55 PM
Clicking on the header is setting the col header as the current cell. Then pressing the ctl-V on it is marking it as changed, and hence CurrentCellValidating is being raised for this header cell. And the code in your CurrectCellvalidating handler is trying to caste the ControlText to a single, and this is why you see the exception. The COntrolText is empty in these header cells and that leads to the exception. I do not know whether this is expected behavior or not. I will forward it to Stefan for his comments.
You can work around it easily enough by make sure your code in CurrentCellValidating is only hit when the proper cell is passed in. You can test the currend row and colindex before hitting your validation code to verify you want to validate the current cell.
If Me.grdArrearsS.CurrentCell.RowIndex > 0 AndAlso Me.grdArrearsS.CurrentCell.ColIndex > 0 Then
''....... do you validation.
You could also use double.TryParse to do the conversion and this would allow you to avoid other exceptions that might arise by trying to use CSng on an string.