C# “无法创建字段的子列表......无法创建”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1130364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 08:55:02  来源:igfitidea点击:

What does "Child list for field ... cannot be created" mean?

c#infragisticssystem.data

提问by Corpsekicker

My C# coded application uses an Infragistics.Win.UltraWinGrid.UltraGrid to display some data. The data is basically a collection of computers. The application is able to filter these computers (like "Workstations", "Servers" etc) for viewing. This is how I filter:

我的 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;
    }

Note that I set the table name to a potentially huge filter string.

请注意,我将表名设置为一个潜在的巨大过滤器字符串。

This is how I use the above method:

这是我如何使用上述方法:

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);

Everything upto that point is fine. UltraGrids have a facility that allows you to choose which columns you want hidden and create new custom columns. When this facility is started an event of the UltraGrid called BeforeColumnChooserDisplayedis fired. Here's my handler:

到那时一切都很好。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;
    }

And here is the ShowCustomColumnChooserDialogmethod implementation:

这是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 is basically a form which adds a little extra to the Infragistics default one. The most important thing that it's code takes care of is this method:

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;
    }

If I step through the code, it's all cool until I exit the event handler (the point at which the control returns to the form). I get an ArgumentException thrown at me onlywhen I try and show the CustomColumnChooser dialog from a grid that displays filtered data. Not the kind that shows the offending line in your code, but the type that brings up a "Microsoft .NET Framework" error message box that says "Unhandled exception has occurred in your application...". This means I can't trace what's causing it. The app doesn't fall apart after that, but the would-be CustomColumnChooser dialog comes up with the container containing nothing but a white background and a big red "X".

如果我单步执行代码,那么在我退出事件处理程序(控件返回表单的点)之前,一切都很酷。只有当我尝试从显示过滤数据的网格中显示 CustomColumnChooser 对话框时,我才会收到一个 ArgumentException 。不是在您的代码中显示违规行的类型,而是显示“Microsoft .NET Framework”错误消息框的类型,其中显示“您的应用程序中发生了未处理的异常...”。这意味着我无法追踪导致它的原因。之后应用程序并没有崩溃,但是可能的 CustomColumnChooser 对话框出现了容器,其中只包含一个白色背景和一个大的红色“X”。

And the stack trace:

和堆栈跟踪:

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)

Child list for field DiscoveryData([Build] = '4 cannot be createdis not very helpful. What does it really mean?

字段 DiscoveryData([Build] = '4 cannot be created) 的子列表不是很有帮助。它的真正含义是什么?

采纳答案by Andrew Corkery

I'm not too well up on WinForms and have never used Infragistics Ultragrid. My guess would be that Child list for field DiscoverData([Build] = '4is thrown deep down in the framework in some of the data-binding code. It seems to be looking for child members of a class called ([Build] = '4as it stops at the dot or period (.) in your string literal.

我对 WinForms 不太熟悉,也从未使用过 Infragistics Ultragrid。我的猜测是字段 DiscoverData([Build] = '4 的子列表在某些数据绑定代码的框架中被抛出。它似乎正在寻找名为([Build] =的类的子成员) '4因为它在您的字符串文字中的点或句点 (.) 处停止。

I try to avoid working with DataSets and DataViews because of some of the crazy hoops they jump through.

我尽量避免使用DataSets 和DataViews,因为它们会跳过一些疯狂的圈套。

Might be worth firing up Reflector and having a poke around System.Windows.Forms.BindingContext

可能值得启动 Reflector 并四处看看 System.Windows.Forms.BindingContext

回答by juFo

Check you DataBindings.

检查你的数据绑定。

The problem is often caused due to your binding path. If you have something like this:

该问题通常是由于您的绑定路径引起的。如果你有这样的事情:

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

you will probably have to update it to another Add-method overload:

您可能必须将其更新为另一个 Add-method 重载:

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