“Child list for field ... cannot be created” 是什么意思?(涉及IT技术)

3

我的C#编写的应用程序使用Infragistics.Win.UltraWinGrid.UltraGrid来显示一些数据。这些数据基本上是计算机的集合。该应用程序能够过滤这些计算机(如“工作站”,“服务器”等)以供查看。以下是我进行筛选的方式:

private DataView FilterTableDataForViewing(DataTable originalTable, string filterString, UltraGrid viewGrid)
    {
        DataView dataView = new DataView(originalTable);
        dataView.RowStateFilter = DataViewRowState.CurrentRows;
        dataView.RowFilter = filterString;

        DataTable filteredTable = dataView.ToTable(originalTable.TableName + "_" + dataView.RowFilter);
        viewGrid.DataSource = filteredTable;
        gridDiscoveryMain.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
        SetFlagImagesAndColumnWidthsOfDiscoveryGrid();
        return dataView;
    }

请注意,我将表名设置为一个可能非常庞大的过滤字符串。
以下是我使用上述方法的方式:
string filterString = "([Build] = '4.0' AND NOT([OS Plus Version] LIKE '%Server%'))";
            filterString += " OR ([Build] = '4.10')";
            filterString += " OR ([Build] = '4.90')";
            filterString += " OR ([Build] = '5.0' AND NOT([OS Plus Version] LIKE '%Server%'))";
            filterString += " OR ([Build] = '5.1')";
            filterString += " OR ([Build] = '6.0' AND ";
            filterString += "(NOT([OS Plus Version] LIKE '%Server%')) OR (NOT([OS] LIKE '%Server%')))";
            FilterTableDataForViewing(dataSet.Tables["DiscoveryData"], filterString, gridDiscoveryMain);

在那之前的一切都很好。UltraGrids有一个功能,允许您选择要隐藏哪些列并创建新的自定义列。当启动此功能时,UltraGrid的一个事件被触发,称为BeforeColumnChooserDisplayed。这是我的处理程序:

private void gridDiscoveryMain_BeforeColumnChooserDisplayed(object sender, BeforeColumnChooserDisplayedEventArgs e)
    {
        if (gridDiscoveryMain.DataSource == null)
            return;

        e.Cancel = true;
        gridDiscoveryMain.DisplayLayout.Override.RowSelectors = DefaultableBoolean.True;
        gridDiscoveryMain.DisplayLayout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.ColumnChooserButton;
        ShowCustomColumnChooserDialog();
        this.customColumnChooserDialog.CurrentBand = e.Dialog.ColumnChooserControl.CurrentBand;
        this.customColumnChooserDialog.ColumnChooserControl.Style = ColumnChooserStyle.AllColumnsWithCheckBoxes;
    }

这里是ShowCustomColumnChooserDialog方法的实现:

private void ShowCustomColumnChooserDialog()
    {
        DataTable originalTable = GetUnderlyingDataSource(gridDiscoveryMain);
        if (this.customColumnChooserDialog == null || this.customColumnChooserDialog.IsDisposed)
        {
            customColumnChooserDialog = new CustomColumnChooser(ManageColumnDeleted);
            customColumnChooserDialog.Owner = Parent.FindForm();
            customColumnChooserDialog.Grid = gridDiscoveryMain;
        }

        this.customColumnChooserDialog.Show();
    }

customColumnChooserDialog基本上是一个表单,它在Infragistics默认的表单上添加了一些额外的功能。最重要的是,它的代码处理的方法是:

private void InitializeBandsCombo( UltraGridBase grid )
    {
        this.ultraComboBandSelector.SetDataBinding( null, null );
        if ( null == grid )
            return;

        // Create the data source that we can bind to UltraCombo for displaying 
        // list of bands. The datasource will have two columns. One that contains
        // the instances of UltraGridBand and the other that contains the text
        // representation of the bands.
        UltraDataSource bandsUDS = new UltraDataSource( );
        bandsUDS.Band.Columns.Add( "Band", typeof( UltraGridBand ) );
        bandsUDS.Band.Columns.Add( "DisplayText", typeof( string ) );

        foreach ( UltraGridBand band in grid.DisplayLayout.Bands )
        {
            if ( ! this.IsBandExcluded( band ) )
            {
                bandsUDS.Rows.Add( new object[] { band, band.Header.Caption } );
            }
        }

        this.ultraComboBandSelector.DisplayMember = "DisplayText";
        this.ultraComboBandSelector.ValueMember= "Band";
        this.ultraComboBandSelector.SetDataBinding( bandsUDS, null );

        // Hide the Band column.
        this.ultraComboBandSelector.DisplayLayout.Bands[0].Columns["Band"].Hidden = true;

        // Hide the column headers.
        this.ultraComboBandSelector.DisplayLayout.Bands[0].ColHeadersVisible = false;

        // Set some properties to improve the look & feel of the ultra combo.
        this.ultraComboBandSelector.DropDownWidth = 0;
        this.ultraComboBandSelector.DisplayLayout.Override.HotTrackRowAppearance.BackColor = Color.LightYellow;
        this.ultraComboBandSelector.DisplayLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns;
        this.ultraComboBandSelector.DisplayLayout.BorderStyle = UIElementBorderStyle.Solid;
        this.ultraComboBandSelector.DisplayLayout.Appearance.BorderColor = SystemColors.Highlight;
    }

如果我逐步执行代码,直到退出事件处理程序(控件返回到窗体的位置),那么一切都很顺利。但是当我尝试从显示过滤数据的网格中显示CustomColumnChooser对话框时,会抛出ArgumentException异常。这不是显示代码中有错的类型,而是弹出一个"Microsoft .NET Framework"错误消息框,其中显示"应用程序中发生未经处理的异常..."。这意味着我无法跟踪导致这个异常的原因。虽然应用程序在此之后并没有崩溃,但应该会出现CustomColumnChooser对话框,但其容器中只有白色背景和一个大大的红色"X"。

堆栈跟踪如下:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ArgumentException: Child list for field DiscoveryData_([Build] = '4 cannot be created.
   at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember)
   at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember)
   at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember)
   at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember)
   at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember)
   at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember)
   at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember)
   at System.Windows.Forms.BindingContext.get_Item(Object dataSource, String dataMember)
   at Infragistics.Win.UltraWinGrid.UltraGridLayout.ListManagerUpdated(BindingManagerBase bindingManager)
   at Infragistics.Win.UltraWinGrid.UltraGridLayout.ListManagerUpdated()
   at Infragistics.Win.UltraWinGrid.UltraGridBase.Set_ListManager(Object newDataSource, String newDataMember)
   at Infragistics.Win.UltraWinGrid.UltraGridBase.SetDataBindingHelper(Object dataSource, String dataMember, Boolean hideNewColumns, Boolean hideNewBands)
   at Infragistics.Win.UltraWinGrid.UltraGridBase.SetDataBinding(Object dataSource, String dataMember, Boolean hideNewColumns, Boolean hideNewBands)
   at Infragistics.Win.UltraWinGrid.UltraGridBase.SetDataBinding(Object dataSource, String dataMember, Boolean hideNewColumns)
   at Infragistics.Win.UltraWinGrid.UltraGridBase.SetDataBinding(Object dataSource, String dataMember)
   at Infragistics.Win.UltraWinGrid.UltraGridColumnChooser.CreateColumnChooserGridDataStructure()
   at Infragistics.Win.UltraWinGrid.UltraGridColumnChooser.Initialize()
   at Infragistics.Win.UltraWinGrid.UltraGridColumnChooser.VerifyInitialized()
   at Infragistics.Win.UltraWinGrid.ColumnChooserGridCreationFilter.BeforeCreateChildElements(UIElement parent)
   at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive)
   at Infragistics.Win.UltraWinGrid.UltraGridUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive)
   at Infragistics.Win.UIElement.VerifyChildElements(Boolean recursive)
   at Infragistics.Win.UltraWinGrid.UltraGridUIElement.InternalInitializeRect(Boolean verify)
   at Infragistics.Win.UltraWinGrid.UltraGridLayout.GetUIElement(Boolean verify, Boolean forceInitializeRect)
   at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(PaintEventArgs pe)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

DiscoveryData([Build] = '4 cannot be created的子列表不是很有用。它到底意味着什么?


我避免了异常被抛出,因为我没有让DataTable的名称过长复杂的筛选字符串。我需要跟踪我是如何进行筛选以用于另一个功能,所以这个变化的影响是巨大的:( 我猜某些东西不喜欢所有的特殊字符?我仍然想知道"无法创建字段......的子列表"到底意味着什么... - Corpsekicker
3个回答

2
我对WinForms不是很了解,也从未使用过Infragistics Ultragrid。我猜测DiscoverData([Build] = '4字段的子列表被深深地嵌入到某些数据绑定代码中的框架中。它似乎正在寻找一个名为([Build] = '4的类的子成员,因为它在你的字符串文字中停在了点号(.)处。

我尽量避免使用DataSetDataView,因为它们会跳过一些疯狂的环节。

值得启动Reflector并查看System.Windows.Forms.BindingContext


0

检查你的数据绑定。

问题通常是由于你的绑定路径导致的。 如果你的情况是这样的:

labelFirstName.DataBindings.Add("Text", "_Person.Info.FName", true, DataSourceUpdateMode.OnPropertyChanged);

你可能需要将其更新为另一个Add方法重载:

labelFirstName.DataBindings.Add("Text", _Person.Info, "FName", true, DataSourceUpdateMode.OnPropertyChanged);

0

我创建了一个新的DataSet并从头开始创建表和列,然后删除了导致此异常的DataSet,并将新的重命名为已删除的名称。

现在它又可以正常工作了。

我的情况是这样的

我在我的窗体上放置了一个DataSet,在可视化设计器中添加了2个每个有2列的表。

在运行时,这些表被填充了数据,但数据从未保存过。

这个方法很好用,直到有一天我遇到了与OP相同的异常。
那么,发生了什么变化?
嗯,什么都没有变化。
这个窗体在VS中是打开的,但是没有进行任何更改。

我经常会遇到这种情况,VS似乎会在打开的文件中做出一些更改,但不告诉我它改变了什么或让我知道它改变了什么,
SVN也没有检测到任何更改,
现在的问题是,VS做出的更改可以编译,但是可视化设计器对它们有很大的问题。

我希望他们停止这样做...

哦,是的,在我忘记之前,我的异常是

无法为字段“project”创建子列表

有趣的是,我没有叫做project的领域!
我确实有另一个数据集,其中有一个名为project的表,但异常没有发生在该数据集上。
在有问题的数据集上,没有叫做Project的字段,也没有叫做Project的表。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接