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

如果我通过代码,它的所有冷却,直至我退出事件处理程序(在该点,控制返回到表格)。我得到了我抛出一个ArgumentException的当我尝试从显示的过滤数据网格显示了CustomColumnChooser对话框。不就是显示你的代码有问题的行的那种,但带来了一个“Microsoft .NET框架”错误消息框,指出该型“发生在应用程序中未处理的异常......”。这意味着我不能跟踪什么导致它。在此之后,应用程序不会崩溃,但想成为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子列表([建设] =“4不能创建是不是非常有帮助。这是什么真正的意思?

有帮助吗?

解决方案

我不太好起来的WinForms和从未使用过的Infragistics的UltraGrid。我的猜测是用于现场DiscoverData是儿童列表([建设] =“4 被抛出在一些数据绑定框架代码深处,似乎在寻找的子成员类调用的([构建] =“4 因为它停止在您的字符串的点或句号(。)文字。

我尽量避免因为一些他们通过跳疯狂的篮球的DataSets和DataViews工作。

可能是值得发射了反射器和具有绕System.Windows.Forms.BindingContext一个戳

其他提示

检查您数据绑定。

在问题经常起因于您的结合路径。 如果你有这样的事情:

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

您可能不得不将其更新到其他附加的方法重载:

labelFirstName.DataBindings.Add("Text", _Person.Info, "FName", true, DataSourceUpdateMode.OnPropertyChanged);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top