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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

"specified cast is not valid"

Thread ID:

Created:

Updated:

Platform:

Replies:

17605 Aug 12,2004 05:34 PM UTC Aug 20,2004 01:34 PM UTC WinForms 13
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On August 12, 2004 05:34 PM UTC

Hi. I have a GDBG that is bound to a DataSet whihc is created programmatically. When I bind to a table (or view) that has data, everything seems to work ok. But when I bind to an empty table, and then attempt to add data to a cell, as soon as I try to leave that cell I get the "specified cast is not valid" message box. I have no idea why this is happening nor do I have a clue as to how to start debugging it. Any ideas? Thanks, Andy

Administrator [Syncfusion]
Replied On August 12, 2004 06:58 PM UTC

You might try various settings of these two properties to see if any combination allows things to work in your case. this.grid.UseListChangedEvent this.grid.OptimizeInsertRemoveCells If you have the source code for our controls, you can use the AssemblyManager (from the Syncfusion Start Menu) to build a debug version of our libraries, and set things up to use these debug libraries. Then you can set the debuuger ot break on exception, and see exactly what code is generating the exception. If you can post a sample project showing the problem, we can do this debug work here.

Administrator [Syncfusion]
Replied On August 13, 2004 10:08 AM UTC

Ok. I tried various combinations of the two options you mentioned w/out success. So I rebuilt with the debug assemblies. The exception is throw somewhere inside the code at the line indicated below with ">>>" which is in GridModelDataBinder.cs in the SaveCellinfo method. ~~~~~~ snippet ~~~~~~~ columnStyle.value = e.Style.CellValue; if (!columnStyle.dirty) { columnStyle.dirty = true; >>> columnStyle.savedValue = pd.GetValue(component); } ~~~~~~ snippet ~~~~~~~ I''ve also attached a text file with the stack-trace at the time of the exception. Any ideas on why that line, or something below it, is throwing an invalid cast exception? In the meantime, I''ll see if I can produce a small test project that duplicates the error. >You might try various settings of these two properties to see if any combination allows things to work in your case. > >this.grid.UseListChangedEvent >this.grid.OptimizeInsertRemoveCells > >If you have the source code for our controls, you can use the AssemblyManager (from the Syncfusion Start Menu) to build a debug version of our libraries, and set things up to use these debug libraries. Then you can set the debuuger ot break on exception, and see exactly what code is generating the exception. > >If you can post a sample project showing the problem, we can do this debug work here. syncfusion_stack_trace_2953.zip

Administrator [Syncfusion]
Replied On August 13, 2004 10:39 AM UTC

The stack was not too helpful for me. The only thing I got from the stack was that you were trying to save a 1 in cell 1,1. Do you see the problem when you click to another cell in the same row, or only when you click into second row that was created? The reason for the question is that clicking off the row triggers a save to the DataSource which would involve saving the cells you have not entered yet. If those fields in the datasource had some constraints on them (like no nulls), then problems could occur. I tried to see the problem in the attached sample using our latest 2.x code base, and could not. I can type 1 in column 1 and leave the cell either to the second column in the same row or to a different row. Can you see the problem with this sample? If not, what kinds of things are different in your code? WindowsApplication9_3833.zip

Administrator [Syncfusion]
Replied On August 16, 2004 11:00 AM UTC

The problem occurs when binding to an empty database table. If I populate a row in the table, then the error does not occur. I''ve attached a small test application that demonstrates the problem. There is a readme.txt file that lists the steps required. >The stack was not too helpful for me. The only thing I got from the stack was that you were trying to save a 1 in cell 1,1. > >Do you see the problem when you click to another cell in the same row, or only when you click into second row that was created? The reason for the question is that clicking off the row triggers a save to the DataSource which would involve saving the cells you have not entered yet. If those fields in the datasource had some constraints on them (like no nulls), then problems could occur. > >I tried to see the problem in the attached sample using our latest 2.x code base, and could not. I can type 1 in column 1 and leave the cell either to the second column in the same row or to a different row. Can you see the problem with this sample? If not, what kinds of things are different in your code? > >WindowsApplication9_3833.zip > > TestApp_2237.zip

Administrator [Syncfusion]
Replied On August 16, 2004 11:13 AM UTC

One theory that we have is that the problem is being caused by something inside the grid code attempting to cast a null value (from the DB) into an object. I''ve seen that such a situation can lead to that invalid cast message. I can trap the condition that there is an empty table (or view) being bound, but I''m not sure how I can handle it outside the grid control code anyway. >The problem occurs when binding to an empty database table. If I populate a row in the table, then the error does not occur. > >I''ve attached a small test application that demonstrates the problem. There is a readme.txt file that lists the steps required. > >>The stack was not too helpful for me. The only thing I got from the stack was that you were trying to save a 1 in cell 1,1. >> >>Do you see the problem when you click to another cell in the same row, or only when you click into second row that was created? The reason for the question is that clicking off the row triggers a save to the DataSource which would involve saving the cells you have not entered yet. If those fields in the datasource had some constraints on them (like no nulls), then problems could occur. >> >>I tried to see the problem in the attached sample using our latest 2.x code base, and could not. I can type 1 in column 1 and leave the cell either to the second column in the same row or to a different row. Can you see the problem with this sample? If not, what kinds of things are different in your code? >> >>WindowsApplication9_3833.zip >> >> > >TestApp_2237.zip > >

Administrator [Syncfusion]
Replied On August 16, 2004 12:52 PM UTC

I think you can avoid teh problem by handling the CurrentCellStartEditing event and explicitly add the row by calling grid.Binder.AddRow if you are in this initial situation.
private void gridDataBoundGrid1_CurrentCellStartEditing(object sender, CancelEventArgs e)
{
	CurrencyManager cm = (CurrencyManager)this.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember];
	if(cm != null && cm.Count == 0 && this.gridDataBoundGrid1.CurrentCell.RowIndex == 1)
	{
		this.gridDataBoundGrid1.Binder.AddNew();
	}
}

Administrator [Syncfusion]
Replied On August 17, 2004 11:06 AM UTC

Clay, That does indeed avoid the exception. Thanks. Is this a bug in the grid control? I would think that the control should be able to handle the situation where it is bound to an empty table w/out requiring the user (programmer) to handle any events (in the basic case presented here). Andy >I think you can avoid teh problem by handling the CurrentCellStartEditing event and explicitly add the row by calling grid.Binder.AddRow if you are in this initial situation. >
>private void gridDataBoundGrid1_CurrentCellStartEditing(object sender, CancelEventArgs e)
>{
>	CurrencyManager cm = (CurrencyManager)this.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember];
>	if(cm != null && cm.Count == 0 && this.gridDataBoundGrid1.CurrentCell.RowIndex == 1)
>	{
>		this.gridDataBoundGrid1.Binder.AddNew();
>	}
>}
>

Administrator [Syncfusion]
Replied On August 17, 2004 11:38 AM UTC

This probably is a bug. I have forwarded it to the grid architect to see if it is something we can get fixed.

Administrator [Syncfusion]
Replied On August 17, 2004 12:55 PM UTC

This problem has been corrected in our code base, but the correction did not make the 2.1.0.9 release which should be available any day now. It should be in the next release.

Administrator [Syncfusion]
Replied On August 19, 2004 12:45 PM UTC

Thanks, Clay.

TJ
Replied On August 20, 2004 12:25 PM UTC

Hey, I''ve had exactly the same problem (using 2.0.5.1), so it was great to find this discussion thread. The CurrentCellStartEditing solution didn''t work for me, though. Binder.AddNew doesn''t seem to create the DataTable''s initial row, which caused problems later when I tried to save changes. I already have code to create the DataRow manually and add it to the DataTable, so once that happened, I had two extra rows displayed instead of one. Anyway, I worked around the whole issue by adding a "fake" row 0 to the DataTable, and hiding it in the GDBG. This works fine. My question: Do you have a rough ETA for a release that will include your fix (Days? Weeks? Months?), and if so, what would the version number be? (I''m trying to decide whether to wait for the fix, or stay with the workaround.) Thanks! Tom

Administrator [Syncfusion]
Replied On August 20, 2004 01:03 PM UTC

2.1.0.9 was released yesterday but did not include this fix. You can use our update noticification web service that will inform you when new updates are available. I do not know when the next public release will be. It is likely the order of weeks/months. You can submit a Direct Trac support incident and request a private build. Those generally can happen in a few days time frame, but would not be a public release that goes through our full test cycle, and would only be the DLLs and not the source (usually).

TJ
Replied On August 20, 2004 01:34 PM UTC

Okay, thanks. I think I''ll stick with the workaround, then, and look into subscribing for that notification service. Cheers, Tom

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.

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

;