Adding Row To Displayed Child Table Fails

B

Bob Day

Using vs 2003, vb.net, sql msde

I have a Parent/Child related datagrid and datatables. When only the parent
is displayed, I can add 200 rows in a loop to the child table with out a
problem and then display these new child table rows. If I display the Child
table first, and then try to add 200 rows, it fails on the first row adding
attempt with the following error. I am only adding rows to the DataSet
Child Table, not updating any datasource.

"A first change exception of type 'System.IndexOutOf RangeExcetpion'
occurred in system.windows.forms.dll



Additional information: Index was outside the bounds of the array."



What is going on?



Bob Day
 
Y

Ying-Shen Yu[MSFT]

Hi Bob,

Thanks for your post!

I'm looking into this problem, however, with limited information I'm not
able to figure out the cause,
could you show me the strack trace message of this exception?
I'd also like to know how you bind your datagrid with the parent/child
tables?
And in your post, you said "if I display child table first... ", does it
mean you set the data member property to a DataRelation object (e.g.
"Suppliers.SuppliersProducts")?


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
 
B

Bob Day

I have found a work around, which seems to be a bug. If there are now rows
in the Child table while displayed (it does not matter if the datasource has
rows or now), then the first row written to it will fail with the error:
"A first change exception of type 'System.IndexOutOf RangeExcetpion'
occurred in system.windows.forms.dll
Additional information: Index was outside the bounds of the array."
The work around is to add a dumby row before the table can be expanded to
display the child table.

But, to answer your questions first,
Displayed = manually displaying by clicking on the + next to the parent
row,which then displays the link relationship Display Detais, and clicking
on that. That displays the child table.

The DataBinding and Relationship itself is created with the follwoing two
subs:

Friend Shared Sub DataGrid_Write_Level_Any_DataBindings_And_TableStyles()
' Purpose: Sets DataBindings and Table Styles used for Details table.
Note that any existing DataRelations and DataBindings are removed before
here by calling method.

' DETAILED is Display Summary with Drill Down Details (saved)
' creae parent/child relationship for Summary/Details DataSet Tables
DLdg.tblMETHODS_SUMMARY_To_tblMETHODS_DETAILS_Data_Relation_Create()

With FormWin_Status
' Bind dg to DataSet's Parent Table (child table is automatically
bound)
.dg_Status_Of_Methods.SetDataBinding(gcCDdg.DS_Methods,
AKA.SQL_tblMETHODS_SUMMARY)

' Assign summary table style

..dg_Status_Of_Methods.TableStyles(AKA.dgts_Methods_Summary_Index).MappingNam
e = gcCDdg.DS_Methods.Methods_Summary.TableName

' Assign details table style

..dg_Status_Of_Methods.TableStyles(AKA.dgts_Methods_Details_Index).MappingNam
e = gcCDdg.DS_Methods.Methods_Details.TableName

End With

**** this is the work around, to simply add a starting row
' create startup row, only needed for DETAILS
tblMETHODS_DETALS_ADD_StartUp_Row()

End Sub

Friend Shared Sub
tblMETHODS_SUMMARY_To_tblMETHODS_DETAILS_Data_Relation_Create()

' Purpose: There are two tables in the DS_Methods DataSet. One is Summary
(i.e. Parent), and one is Details (i.e. Child). This creates a parent/child
releationship between the two tables, the relationship being called "Display
Details", so that the info in the details is related to a specific summary
row.

' instantiate Parent Column Summary

Dim Summary_ParentColumn As New DataColumn

' load value of datacolumn for summary parent, which is Primary Key

Summary_ParentColumn =
gcCDdg.DS_Methods.Methods_Summary.fld_Methods_Summary_Table_IDColumn

' Instantiate child column for Details

Dim Details_ChildColumn As New DataColumn

' load value of datacolumn for details child, which is the Foreign Key

Details_ChildColumn =
gcCDdg.DS_Methods.Methods_Details.fld_FK_Methods_Summary_Table_IDColumn

' Create a DataRelation , and add it to the DataRelation Coleciton

Dim Data_Relation As New DataRelation(AKA.RelationshipNameDisplayDetails,
Summary_ParentColumn, Details_ChildColumn)

' must add the parent child relationship for summary with details

gcCDdg.DS_Methods.Relations.Add(Data_Relation)

End Sub



"Ying-Shen Yu[MSFT]" said:
Hi Bob,

Thanks for your post!

I'm looking into this problem, however, with limited information I'm not
able to figure out the cause,
could you show me the strack trace message of this exception?
I'd also like to know how you bind your datagrid with the parent/child
tables?
And in your post, you said "if I display child table first... ", does it
mean you set the data member property to a DataRelation object (e.g.
"Suppliers.SuppliersProducts")?


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
 
Y

Ying-Shen Yu[MSFT]

Hi Bob,

I'm glad to hear you have found a work around.

I read the code snippet in your reply, it seems ok, and I rewrote it in c#
to try to repro this problem, but I'm not able to repro it. If you still
care about this issue, could you send me a small repro sample for this?

Thanks.


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top