Errors adding a new row


Author
Message
Daniel Essin
Daniel Essin
StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)
Group: Forum Members
Posts: 235, Visits: 309
I've got the grid, businessGindingSource and BO mentioned earlier and a data navbar.



I've got this code in the BO:

private void ResultDefs_SetDefaultValues()

{

this.ResultDefId = Guid.NewGuid();

this.OccurrenceValue = 0;

}



When I click add on the data nav bar I get invalid cast errors in the code below both before and after the SetDefaultValues method is executed. I'm confused.



public System.Int32 OccurrenceValue

{

get

{

return (System.Int32)this.CurrentRow["OccurrenceValue"];

}

set

{

this.CurrentRow["OccurrenceValue"] = value;

}

}

public System.Guid ResultDefId

{

get

{

return (System.Guid)this.CurrentRow["ResultDefId"];

}

set

{

this.CurrentRow["ResultDefId"] = value;

}

}



Please help. Thanks,

Dan
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
When you get the invalid cast errors, are they coming from DBNull.Value values, or are they something different?  My only guess is that the navbar might be trying to bind the controls to the grid before they are actually populated with non NULL values.  What does the detail within the exception contain?
Daniel Essin
Daniel Essin
StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)
Group: Forum Members
Posts: 235, Visits: 309
This exception occurs after the SetDefaultValues event has fired. It's a guid key and I don't have any special null value handling defined in the BO.



This is the exception:

System.InvalidCastException was unhandled by user code

Message="Specified cast is not valid."

Source="BusinessObjectLibrary"

StackTrace:

at DM.Library.ResultDefs.get_ResultDefId() in E:\_work.SF\DM\BusinessObjectLibrary\ResultDefs.Designer.cs:line 300

at DM.Library.ResultDefs.Field_ResultDefId_Descriptor.GetValue(Object component) in E:\_work.SF\DM\BusinessObjectLibrary\ResultDefs.Designer.cs:line 755

at DevExpress.Data.Helpers.BaseListDataControllerHelper.GetRowValue(Int32 listSourceRow, Int32 column)

at DevExpress.Data.DataController.GetRowValue(Int32 controllerRow, Int32 column)

at DevExpress.Data.BaseListSourceDataController.GetRowValue(Int32 controllerRow, Int32 column)

at DevExpress.XtraGrid.Views.Base.ColumnView.GetRowCellValue(Int32 rowHandle, GridColumn column)

at DevExpress.XtraGrid.Views.Grid.GridView.GetRowCellValue(Int32 rowHandle, GridColumn column)

at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcRowCellDrawInfo(GridDataRowInfo ri, GridColumnInfoArgs ci, GridCellInfo cell, GridColumnInfoArgs nextColumn, Boolean calcEditInfo)

at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcRowCellsDrawInfo(GridDataRowInfo ri, GridColumnsInfo columnsInfo)

at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcDataRow(GridDataRowInfo ri, GridRow row, GridRow nextRow)

at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcRowsDrawInfo()

at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcAfterVertScrollCore(Graphics g, Rectangle bounds, Boolean useCache)

at DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcAfterVertScroll(Graphics g, Rectangle bounds, Boolean useCache)

at DevExpress.XtraGrid.Views.Grid.GridView.RefreshRows(Boolean useCache, Boolean afterScroll)

at DevExpress.XtraGrid.Views.Grid.GridView.CalculateDataCore()

at DevExpress.XtraGrid.Views.Grid.GridView.CalculateData()

at DevExpress.XtraGrid.Views.Base.BaseView.CheckViewInfo()

at DevExpress.XtraGrid.Views.Grid.GridView.RefreshRows(Boolean useCache, Boolean afterScroll)

at DevExpress.XtraGrid.Views.Grid.GridView.DoTopRowIndexChanged(Int32 prevTopRowIndex)

at DevExpress.XtraGrid.Views.Grid.GridView.InternalSetTopRowIndex(Int32 newTopRowIndex)

at DevExpress.XtraGrid.Views.Grid.GridView.set_TopRowIndex(Int32 value)

at DevExpress.XtraGrid.Views.Grid.GridView.MakeRowVisibleCore(Int32 rowHandle, Boolean invalidate)

at DevExpress.XtraGrid.Views.Grid.GridView.DoChangeFocusedRow(Int32 currentRowHandle, Int32 newRowHandle, Boolean raiseUpdateCurrentRow)

at DevExpress.XtraGrid.Views.Base.ColumnView.DoChangeFocusedRowInternal(Int32 newRowHandle, Boolean updateCurrentRow)

at DevExpress.XtraGrid.Views.Grid.GridView.DevExpress.Data.IDataControllerValidationSupport.OnCurrentControllerRowChanged()

at DevExpress.Data.CurrencyDataController.OnCurrentControllerRowChanged()

at DevExpress.Data.CurrencyDataController.OnCurrentControllerRowChanging(Int32 oldControllerRow, Int32 newControllerRow)

at DevExpress.Data.CurrencyDataController.set_CurrentControllerRow(Int32 value)

at DevExpress.Data.CurrencyDataController.OnCurrencyManager_PositionChanged(Object sender, EventArgs e)

at System.EventHandler.Invoke(Object sender, EventArgs e)

at System.Windows.Forms.CurrencyManager.OnPositionChanged(EventArgs e)



The data of the current row is visible in the attachment. The key field is blank even though the SetDefaultValues event has fired.



The nav bar is a ComponentOne nav bar that seems to be able to use your businesBindingSource as a datasource.
Attachments
ResultDefs.jpg (177 views, 384.00 KB)
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
What happens if you try to access the ResultDefId property through the watch window?  Do you get the same InvalidCastException? 
Daniel Essin
Daniel Essin
StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)
Group: Forum Members
Posts: 235, Visits: 309
Yes. Same error in the watch window.
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
If you put this in the watch window, what is the value?

this.CurrentTable.Columns["ResultDefId"].DataType

Does it show {System.Guid}?

Daniel Essin
Daniel Essin
StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)
Group: Forum Members
Posts: 235, Visits: 309
yes it's system.guid
Daniel Essin
Daniel Essin
StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)
Group: Forum Members
Posts: 235, Visits: 309
OK, I've found the navigator that is embedded in the DevExp grid and have enabled it. When I click its add button I get a different error in:

Protected Overridable Sub OnListChanged(ByVal e As ListChangedEventArgs)

RaiseEvent ListChanged(Me, e)

End Sub



System.IndexOutOfRangeException was unhandled by user code

Message="Index was outside the bounds of the array."

Source="DevExpress.Data.v6.1"

StackTrace:

at DevExpress.Data.VisibleIndexCollection.AddVisibleDataRows(GroupRowInfo rowInfo)

at DevExpress.Data.VisibleIndexCollection.BuildVisibleIndexesEx(GroupRowInfo groupRow, Boolean expandAll, Boolean expanded)

at DevExpress.Data.VisibleIndexCollection.BuildVisibleIndexesEx(GroupRowInfo groupRow, Boolean expandAll, Boolean expanded)

at DevExpress.Data.VisibleIndexCollection.BuildVisibleIndexes(Int32 visibleCount, Boolean allowNonGroupedList, Boolean expandAll)

at DevExpress.Data.DataController.OnBindingListChangedCore(ListChangedEventArgs e)

at DevExpress.Data.CurrencyDataController.OnBindingListChangedCore(ListChangedEventArgs e)

at DevExpress.Data.DataController.OnBindingListChanged(ListChangedEventArgs e)

at DevExpress.Data.CurrencyDataController.RaiseOnBindingListChanged(ListChangedEventArgs e)

at DevExpress.Data.Helpers.ListDataControllerHelper.OnBindingListChanged(Object sender, ListChangedEventArgs e)

at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)

at MicroFour.StrataFrame.Business.BusinessBindingSource.OnListChanged(ListChangedEventArgs e)

at MicroFour.StrataFrame.Business.BusinessBindingSource.BusinessObject_CurrentView_ListChanged(Object sender, ListChangedEventArgs e)

at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)

at System.Data.DataView.OnListChanged(ListChangedEventArgs e)



This exception occurrs 8 times before ResultDefs_SetDefaultValues() is reached.

Daniel Essin
Daniel Essin
StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)
Group: Forum Members
Posts: 235, Visits: 309
Please note that this issue is not resolved and that I have been unable to work since last Thursday.
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
I apologize for the slow response, Daniel, Trent and I are both out of town this week. 

I am not sure what is causing your problem.  The row has already been added to the business object's internal DataTable when the ListChanged event is raised, so it should not be throwing an index out of range exception.  Without stepping through your application and checking the counts and the CurrentRowIndex within your business object, and determining what index the grid is attempting to access, I am not sure what where the error is coming from. 

I am going to attempt to test the issue on a DevExpress grid and reproduce the problem.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search