2009-07-15 19 views
2

我的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有一個工具,可以讓你選擇你想要隱藏的列並創建新的自定義列。當這個設施啓動時,稱爲BeforeColumnChooserDisplayed的UltraGrid事件被觸發。這裏是我的處理程序:

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 Framework」錯誤消息框的類型,它顯示「應用程序中發生了未處理的異常......」。這意味着我無法追查是什麼原因造成的。在此之後,應用程序不會崩潰,但想成爲CustomColumnChooser對話框出現包含什麼,但白色背景和大紅色的「X」的容器:

Big Red X

而且堆棧跟蹤:

有關調用 即時(JIT)調試代替此對話框的詳細信息,請參閱此消息的結尾。

**************異常文本************** System.ArgumentException:字段DiscoveryData的子列表_([Build] =' 4不能被創建。 在System.Windows.Forms.BindingContext.EnsureListManager(DataSource對象,字符串數據成員) 在System.Windows.Forms.BindingContext.EnsureListManager(DataSource對象,字符串數據成員) 在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.E在Infragistics.Win上的System.Windows.Forms.BindingContext.get_Item(Object dataSource,String dataMember) at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource,String dataMember) (對象dataSource,String dataMember) UltraWinGrid.UltraGridLayout.ListManagerUpdated(BindingManagerBase BindingManager的) 在Infragistics.Win.UltraWinGrid.UltraGridLayout.ListManagerUpdated() 在Infragistics.Win.UltraWinGrid.UltraGridBase.Set_ListManager(對象newDataSource,字符串newDataMember) 在Infragistics.Win.UltraWinGrid.UltraGridBase。 SetDataBindingHelper(DataSource對象,字符串數據成員,布爾hideNewColumns,布爾hideNewBands) 在Infragistics.Win.UltraWinGrid.UltraGridBase.SetDataBinding(DataSource對象,字符串數據成員,布爾hideNewColumns,布爾hideNewBands) 在Infragistics.Win.UltraWinGrid.UltraGridBase.SetDataBinding( Object dataSource,String dataMember,Boolean hideNewColumns) at Infragistics.Win.UltraWinGrid.UltraGridBase.SetDataBinding(Object dataSource,String dataMember) 在Infragistics.Win.UltraWinGrid.UltraGridColumnChooser.CreateColumnChooserGridDataStructure() 在Infragistics.Win.UltraWinGrid.UltraGridColumnChooser.Initialize() 在Infragistics.Win.UltraWinGrid.UltraGridColumnChooser.VerifyInitialized() 在Infragistics.Win.UltraWinGrid.ColumnChooserGridCreationFilter.BeforeCreateChildElements (母體的UIElement) 在Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement,布爾遞歸) 在Infragistics.Win.UltraWinGrid.UltraGridUIElement.VerifyChildElements(ControlUIElementBase controlElement,布爾遞歸) 在Infragistics.Win.UIElement.VerifyChildElements(布爾遞歸) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.InternalInitializeRect(布爾驗證) 在Infragistics.Win.UltraWinGrid.UltraGridLayout.GetUIElement(布爾驗證,布爾forceInitializeRect) 在Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(PaintEventArgs pe) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,Int16圖層布爾disposeEventArgs) 在System.Windows.Forms.Control.WmPaint(消息&米) 在System.Windows.Forms.Control.WndProc(消息&米) 在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& 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無法創建不是很有幫助。這是什麼意思?

+0

嗯,我避免了例外通過不使DataTable的名字被拋出那長的複雜的過濾器串。我需要跟蹤我是如何過濾另一個功能,所以這種變化的影響是巨大的:( 我猜的東西不喜歡所有的特殊字符? 我仍然想知道究竟是什麼「無法創建字段的子列表「表示... – Corpsekicker 2009-07-15 14:14:13

回答

2

我不太喜歡WinForms,也從未使用過Infragistics Ultragrid。我的猜測是在某些數據綁定代碼中,字段DiscoverData([Build] ='4)的子列表被拋入框架內部,它似乎在尋找名爲([建設] =「4因爲它會停在你的字符串點或者句號(。)文字。

我儘量避免與DataSet S和因爲一些他們通過跳瘋狂的籃球的DataView s工作。

可能值得引發反射器並有一個捅System.Windows.Forms.BindingContext

0

Chec你DataBindings。

問題通常是由於您的綁定路徑造成的。 如果你有這樣的事情:

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

你可能要更新到另一個附加的方法重載:

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