I am trying to display two datatables with parent-child relationship using grid. The first time display is fine. It comes up with two bands. The problem comes when I try to change the dataset and reuse it for a new grid later. The exception is InvalidContaintException: Cannot have a relationship between tables in different DataSets.
This is what I did: I have one dataset containing two table A & B, with A as parent and B as child in the relationship. I set the datasource of the grid to table A, and the grid display A as Band 0 and B and Band 1. Then, I delete the relationship, delete table B, recreate table B and add the relationship from A to B again. Now I create a new grid (old grid is not used anymore and get disposed), set the datasource of the new grid to table A. Here is when the exception happens.
Here is callstack:
System.Data.dll!System.Data.DataRelation.CheckState() + 0x165 bytes System.Data.dll!System.Data.DataRelation.CheckStateForProperty() + 0x21 bytes System.Data.dll!System.Data.DataRelation.ChildTable.get() + 0xa bytes System.Data.dll!System.Data.DataSet.FindTable(System.Data.DataTable baseTable, System.ComponentModel.PropertyDescriptor[] props = {System.ComponentModel.PropertyDescriptor[1]}, int propStart = 0) + 0xbd bytes System.Data.dll!System.Data.DataView.System.ComponentModel.ITypedList.GetItemProperties(System.ComponentModel.PropertyDescriptor[] listAccessors) + 0x57 bytes System.Windows.Forms.dll!System.Windows.Forms.ListBindingHelper.GetListItemProperties(object list, System.ComponentModel.PropertyDescriptor[] listAccessors) + 0x79 bytes System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.GetItemProperties(System.ComponentModel.PropertyDescriptor[] listAccessors) + 0xa bytes System.Windows.Forms.dll!System.Windows.Forms.RelatedCurrencyManager.GetItemProperties(System.ComponentModel.PropertyDescriptor[] listAccessors) + 0x5a bytes System.Windows.Forms.dll!System.Windows.Forms.RelatedCurrencyManager.GetItemProperties() + 0xa bytes Infragistics2.Win.v8.3.dll!Infragistics.Win.DataBindingUtils.GetItemProperties(System.Windows.Forms.BindingManagerBase bm = {System.Windows.Forms.RelatedCurrencyManager}, Infragistics.Win.DataBindingUtils.ValuePropertyDescriptorCreator customDescriptorCreator = {Method = {System.ComponentModel.PropertyDescriptor GetItemPropertiesCreator(System.Type, System.String)}}) + 0x2a bytes > Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridBand.GetItemPropertiesHelper() Line 7391 + 0x42 bytes C# Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridBand.InitColumns(Infragistics.Win.UltraWinGrid.UltraGridBand[] oldBands = null) Line 7485 + 0x8 bytes C# Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridBand.InitListManager(System.Windows.Forms.BindingManagerBase bindingManager = {System.Windows.Forms.RelatedCurrencyManager}, string dataMember = "securityCashflowRelationship_AsRow", Infragistics.Win.UltraWinGrid.UltraGridBand[] oldBands = null) Line 7001 + 0xb bytes C# Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridColumn.InitPropertyDescriptor(System.ComponentModel.PropertyDescriptor propertyDescriptor = {System.Data.DataRelationPropertyDescriptor}, Infragistics.Win.UltraWinGrid.UltraGridBand[] oldBands = null) Line 2715 + 0x13 bytes C# Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridBand.InitColumns(Infragistics.Win.UltraWinGrid.UltraGridBand[] oldBands = null) Line 7695 + 0x10 bytes C# Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridBand.InitListManager(System.Windows.Forms.BindingManagerBase bindingManager = {System.Windows.Forms.CurrencyManager}, string dataMember = "", Infragistics.Win.UltraWinGrid.UltraGridBand[] oldBands = null) Line 7001 + 0xb bytes C# Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridLayout.ListManagerUpdated(System.Windows.Forms.BindingManagerBase bindingManager = {System.Windows.Forms.CurrencyManager}) Line 4782 + 0x2b bytes C# Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridLayout.ListManagerUpdated() Line 4558 + 0x29 bytes C# Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridBase.Set_ListManager(object newDataSource = {OriginalTable}, string newDataMember = "") Line 2938 + 0x15 bytes C# Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridBase.VerifyDataSourceAttached() Line 1880 + 0x26 bytes C# Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.UltraGridBase.OnCreateControl() Line 1442 + 0x8 bytes C# System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible) + 0x181 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl() + 0x24 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.ControlCollection.Add(System.Windows.Forms.Control value = {InteractiveDataFIA.BondEdge.CMSControls.CmsRichGrid}) + 0x147 bytes
Thanks,
Zongwen
Zongwen,
I see that you've already created a support case for this issue.
As you've already been notified thrrough the case, we now believe that this issue is caused by the .NET BindingManager, as opposed to by WinGrid. Clearing the grid's DataSource didn't prevent the issue from occurring. We used an alternate approach of removing the grid from the panel, unhooked its InitializeLayout event, and also explicitly disposed it, all before making changes to the DataSet, and all with the same result.
We also found that the same behavior occurs with the .NET DataGridView control. This required adding two DataGridView controls to the form, both whose DataSource was set to the DataTable, and the second with its DataMember set to the name of your DataRelation. This encountered the same exception, only the exception was left unhandled.
I also see that you're working with the Developer Support Engineer to see what alternative approaches may be available to get the end results you're after. This will require an alternate approach, since the BindingManager isn't getting the desired information to controls on the form.
Hi Zongwen,
I took a look at your sample and it appears that the grid might be holding on to the old BindingManager. I think this is a bug. I'm going to forward this thread over to the Infragistics Developer Support team so they can write this up and have it reviewed.
In the mean time, you should be able to work around this by setting the grid's DataSource to null before you make your changes and then set it back after all the changes are complete.
Hi Mike,
I only have one dataset, and the data table is created directly from the dataset. For some reason, first time it works, but not after that. I created a sample program to replicate the problem. Notice that if you click multiple times on the Test button in the form, and setup Visual Studio to break on any exception, the exception will happen.
Please find my sample in the attachment.
It looks like the error is coming from the DataSource, no the grid. Somehow, the Relationship in your data source is trying to relate 2 tables that are not contained in the same DataSet. Perhaps when you created the second table, you forgot to add it to the DataSet before you created the Relationship?