首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >“字段的子列表...无法创建”是什么意思?

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

Stack Overflow用户
提问于 2009-07-15 09:31:00
回答 2查看 13.5K关注 0票数 3

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

代码语言:javascript
复制
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;
    }

注意,我将表名设置为一个可能很大的筛选器字符串。

这就是我如何使用上面的方法:

代码语言:javascript
复制
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有一个工具,允许您选择要隐藏的列并创建新的自定义列。当此工具启动时,将触发一个名为BeforeColumnChooserDisplayed的UltraGrid事件。这是我的处理程序:

代码语言:javascript
复制
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方法的实现:

代码语言:javascript
复制
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基本上是一个表单,它在InFragurs默认表的基础上增加了一点额外的内容。它的代码处理的最重要的事情就是这个方法:

代码语言:javascript
复制
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;
    }

如果我单步执行代码,在退出事件处理程序(控件返回到窗体的点)之前,一切都很酷。当我尝试从一个显示filtered的网格中显示CustomColumnChooser对话框时,我得到了一个抛出的。不是那种在代码中显示有问题的行的类型,而是那种显示“微软.NET框架”错误消息框的类型,该消息框显示“您的应用程序中发生了未处理的异常...”。这意味着我不能追踪是什么引起的。这个应用程序在那之后不会崩溃,但想要成为CustomColumnChooser的对话框出现了一个容器,里面只有一个白色的背景和一个大大的红色"X“。

和堆栈跟踪:

代码语言:javascript
复制
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)

字段Build的Build子列表(DiscoveryData= '4 cannot be created不是很有用。它到底是什么意思?)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-07-23 13:05:54

我对WinForms不是很了解,也从来没有用过Infragistics。我的猜测是字段DiscoverData(Build = '4 )的Build子列表在一些数据绑定代码中被抛出到框架的深层,它似乎是在寻找名为(Build = '4 )的类的子成员,因为它在字符串文字中的点号或句点(.)处停止。

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

可能值得启动Reflector并在System.Windows.Forms.BindingContext周围戳一戳

票数 2
EN

Stack Overflow用户

发布于 2011-12-09 00:36:31

看看你,DataBindings。

这个问题通常是由你的绑定路径引起的。如果你有这样的东西:

代码语言:javascript
复制
labelFirstName.DataBindings.Add("Text", "_Person.Info.FName", true, DataSourceUpdateMode.OnPropertyChanged);

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

代码语言:javascript
复制
labelFirstName.DataBindings.Add("Text", _Person.Info, "FName", true, DataSourceUpdateMode.OnPropertyChanged);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1130364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档