Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1233
Grid Columns and Rows not accessible
posted

Attempting to create a multi-select drop-down, using an ultratexteditor, a dropdowneditorbutton, and an ultragrid, I am having trouble accessing the rows and columns of the grid.

 I have tried adding unbound columns, using an ultradatasource, and numerous other approaches.  Currently, I created a form with a grid and an ultradatasource, and then ported the designer code into my control initialization.

 No matter what I try, _grid.Bands[0].Columns.Count is always 0.  _grid.Rows.Count is also always 0.  However, the dropdown grid does have rows and columns, and the multi-select feature works well.  I need access to the columns so that I can change the column header.  I tried accessing via rows to access cells[0].Column.Header.

I have also reflected into the code to try to determine if a flag is set during initialization that would prevent the property collections from initializing, but I can't seem to find anything.

Can you please help me understand what I might need to do to access the grid columns?  I am posting the initialization code, which is a little lengthy.

 

private DropDownEditorButton _dropDownEditorButton;

private BaseGrid _grid;

private void InitializeComponent()

{

_grid =
new BaseGrid();

_grid.InitializeGrid();

_dropDownEditorButton =
new DropDownEditorButton { Control = _grid };_dataSource = new BaseDataSource();

_grid.DataSource = _dataSource;

((ISupportInitialize)(_grid)).BeginInit();

((ISupportInitialize)(_dataSource)).BeginInit();

// create data bands and columns

var selectedDataColumn = new UltraDataColumn("Selected") {DataType = typeof (bool)};

var displayDataColumn = new UltraDataColumn("DisplayMember") {DataType = typeof (string)};

_dataSource.Band.Key = "Items";

_dataSource.Band.Columns.AddRange(new object[{selectedDataColumn, displayDataColumn});

var selectedGridColumn = new UltraGridColumn("Selected");selectedGridColumn.Header.Caption = "Selected";

selectedGridColumn.Header.VisiblePosition = 0;

var displayGridColumn = new UltraGridColumn("DisplayMember");

displayGridColumn.Header.Caption = "DisplayMember";

displayGridColumn.Header.VisiblePosition = 0;

var band = new UltraGridBand("Items", -1)

{

ColHeadersVisible =
true,

IndentationGroupByRow = 0,

IndentationGroupByRowExpansionIndicator = 0,

ExcludeFromColumnChooser =
ExcludeFromColumnChooser.True,

Override =

{

AllowRowFiltering =
DefaultableBoolean.False,

AllowRowLayoutColMoving = Infragistics.Win.Layout.GridBagLayoutAllowMoving.None,

BorderStyleRow = UIElementBorderStyle.Solid,HeaderPlacement = HeaderPlacement.FixedOnTop

}

};

band.Columns.AddRange(
new object[ { selectedGridColumn, displayGridColumn });

 

_grid.DisplayLayout.BandsSerializer.Add(band);

_grid.DisplayLayout.ColumnChooserEnabled =
DefaultableBoolean.False;_grid.DisplayLayout.Bands[0].ExcludeFromColumnChooser = ExcludeFromColumnChooser.True;

_grid.Height = 150;

_grid.DisplayLayout.ScrollBounds = ScrollBounds.ScrollToFill;

((System.ComponentModel.ISupportInitialize)(this._grid)).EndInit();((System.ComponentModel.ISupportInitialize)(this._dataSource)).EndInit();

 

this.ButtonsRight.Add(_dropDownEditorButton);

 

this.AfterEditorButtonCloseUp += new EditorButtonEventHandler(MultiSelectGridCombo_AfterEditorButtonCloseUp);

}

 

/// <summary>

/// Sets data source

/// </summary>

/// <typeparam name="T">Object Type</typeparam>

/// <param name="dataSource">IList of types</param>

public void SetDataSource<T>(IList<T> dataSource)

{

DesignByContract.
Check.Require(!string.IsNullOrEmpty(DisplayMember), "Display Member not set before binding multi-select combo.");

 

var bindingSource = new BindingList<GridItem>();

foreach (var item in dataSource)

bindingSource.Add(GridItem.Create(item, DisplayMember));

_grid.SetDataBinding(bindingSource, null);

if (_grid.Rows.Count > 0)if (_grid.Rows[0].Cells.Count >= 1)

_grid.Rows[0].Cells[1].Column.Header.Caption = DisplayCaption;

}

In this last routine, Rows.Count always == 0, even though the data does bind correctly.