私の 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);
その時点まではすべて問題ありません。UltraGrid には、非表示にする列を選択して新しいカスタム列を作成できる機能があります。この機能が開始されると、呼び出された 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 の子リストはあまり役に立ちません。それは実際にはどういう意味ですか?