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

InvalidCastException with new version 4.2

GridRecordRow recRow = modelCellStyle.TableCellIdentity.DisplayElement as GridRecordRow;
Object lineObj = recRow.ParentRecord.GetValue("SourceLine");

recRow.ParentRecord throws the exception

System.InvalidCastException: Specified cast is not valid.
at Syncfusion.Windows.Forms.Grid.Grouping.GridRecordRow.get_ParentRecord()
at Syncfusion.Windows.Forms.Grid.Grouping.GridGroupingControl.OnTableControlCurrentCellActivated(GridTableControlEventArgs e)
at Syncfusion.Windows.Forms.Grid.Grouping.GridControlBaseEventsTarget.OnCurrentCellActivated(EventArgs e)
at Syncfusion.Windows.Forms.Grid.GridControlBase.OnCurrentCellActivated(EventArgs e)
at Syncfusion.Windows.Forms.Grid.Grouping.GridTableControl.OnCurrentCellActivated(EventArgs e)
at Syncfusion.Windows.Forms.Grid.GridControlBase.RaiseCurrentCellActivated()
at Syncfusion.Windows.Forms.Grid.GridCurrentCell.Activate(Int32 rowIndex, Int32 colIndex, GridSetCurrentCellOptions options)
at Syncfusion.Windows.Forms.Grid.GridCurrentCell.MoveTo(Int32 rowIndex, Int32 colIndex, GridSetCurrentCellOptions options, Boolean discardChanges)
at Syncfusion.Windows.Forms.Grid.GridCurrentCell.MoveTo(Int32 rowIndex, Int32 colIndex, GridSetCurrentCellOptions options)
at Syncfusion.Windows.Forms.Grid.Grouping.GridTableControl.Table_CurrentRecordContextChange(Object sender, CurrentRecordContextChangeEventArgs e)
at Syncfusion.Windows.Forms.Grid.Grouping.GridTableModel.OnCurrentRecordContextChange(CurrentRecordContextChangeEventArgs e)
at Syncfusion.Windows.Forms.Grid.Grouping.GridTableModel.Syncfusion.Grouping.ITableEventsTarget.OnCurrentRecordContextChange(CurrentRecordContextChangeEventArgs e)
at Syncfusion.Grouping.TableDescriptor.Syncfusion.Grouping.ITableEventsTarget.OnCurrentRecordContextChange(CurrentRecordContextChangeEventArgs e)
at Syncfusion.Grouping.Table.OnCurrentRecordContextChange(CurrentRecordContextChangeEventArgs e)
at Syncfusion.Windows.Forms.Grid.Grouping.GridTableBase.OnCurrentRecordContextChange(CurrentRecordContextChangeEventArgs e)
at Syncfusion.Windows.Forms.Grid.Grouping.GridTable.OnCurrentRecordContextChange(CurrentRecordContextChangeEventArgs e)
at Syncfusion.Grouping.Table.NotifyEnterRecordComplete(Boolean success)
at Syncfusion.Grouping.CurrentRecordManager.EnterRecord(Element record)
at Syncfusion.Grouping.CurrentRecordManager.NavigateTo(Element record, Boolean cancelEditIfNotValid, Boolean scrollInView)
at Syncfusion.Grouping.CurrentRecordManager.NavigateTo(Record record)
at Syncfusion.Grouping.Record.SetCurrent()
at Syncfusion.Windows.Forms.Grid.Grouping.GridGroupingControl.OnEnter(EventArgs e)
at System.Windows.Forms.Control.NotifyEnter()
at System.Windows.Forms.ContainerControl.UpdateFocusedControl()

5 Replies

SM Scott Mercer July 21, 2006 07:39 PM UTC

I wanted to add that this exception was not thrown in version 4.1.0.63, which was our previously installed version of Syncfusion Essential Studio.

--Scott


AD Administrator Syncfusion Team July 24, 2006 09:28 AM UTC

Hi,

Sorry for the inconvenience. The sample works fine for me, and I am not able to see the mentioned issue here. I have attached the sample here. Can you able to see the issue in the attached sample? Or can you please tell me how to reproduce the issue in the attached sample so that we can get back soon with a solution at the earliest.

Here is a sample.
http://www.syncfusion.com/Support/user/uploads/DeleteRecords_ac8d47f8.zip

Regards,
Haneef


MN Martin Nitschke July 25, 2006 03:31 PM UTC

Hi,

I used the ACC sample database, you may have to change the connection string. If you run the app, you will get the exception right away.

In my real app, I have the ShowNewRecordBeforeDetails set to true. When I go to click any cell, that particular row activates first and thus it throws an exception.

The purpose of the code I have attached is to show you the exception that is happening.

>Hi,

Sorry for the inconvenience. The sample works fine for me, and I am not able to see the mentioned issue here. I have attached the sample here. Can you able to see the issue in the attached sample? Or can you please tell me how to reproduce the issue in the attached sample so that we can get back soon with a solution at the earliest.

Here is a sample.
http://www.syncfusion.com/Support/user/uploads/DeleteRecords_ac8d47f8.zip

Regards,
Haneef


GroupingGridSample0.zip


AD Administrator Syncfusion Team July 26, 2006 09:06 AM UTC

Hi Martin,

Try this code snippet to resolve this issue. Please find the code snippet below.

Element el = modelCellStyle.TableCellIdentity.DisplayElement;
GridRecord parent = el.ParentRecord as GridRecord;
if( parent != null )
{
Console.WriteLine(parent);
}

Here is a modified sample.
http://www.syncfusion.com/Support/user/uploads/GroupingGridSample_65760474.zip

Let me know if this helps.
Best Regards,
Haneef


MN Martin Nitschke July 26, 2006 03:53 PM UTC

Yes, it works. The "new row" cell gets activated first, and that doesn''t contain the parent record. After I do the null check, the row I clicked on is activated and it has a parent record so the code works. In previous versions, my code worked. I believe the "new row" was not getting activated first, though I don''t know for sure. For right now this works, but maybe it is a bug in the code that you can look into so this event isn''t firing twice.

Thanks,
Martin

>Hi Martin,

Try this code snippet to resolve this issue. Please find the code snippet below.

Element el = modelCellStyle.TableCellIdentity.DisplayElement;
GridRecord parent = el.ParentRecord as GridRecord;
if( parent != null )
{
Console.WriteLine(parent);
}

Here is a modified sample.
http://www.syncfusion.com/Support/user/uploads/GroupingGridSample_65760474.zip

Let me know if this helps.
Best Regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon