Ceridan
Ceridan

Reputation: 2516

How to properly set DataSource for DevExpress BandedGridView with dynamic number of bands and columns

I'm using BandedGridView for WinForms. And I get information about BandedGridView structure (number of bands and columns) only on runtime. So I have to fill it manually. I can properly create full structure, but I can't understand how to fill it with data. I try to do it in 2 ways:

1.Using GridControl.DataSource property. But here I have problem, because I have dynamic number of columns so I can't create static class which will represent GridViewRow where class properties will represent column fields. I just have data in this form: List (represents each row) and inside OuterClass I have property with type List (represents each Column in GridView). I try to create dynamic objects which represents full row and set to the GridControl.DataSource property BindingList but this time it fires NullReferenceException on binding. Top of stack trace are:

DevExpress.XtraGrid.Columns.GridColumn.get_ColumnType() in DevExpress.XtraGrid.Views.Base.ColumnView.GetColumnDefaultRepositoryItem(GridColumn column) in DevExpress.XtraGrid.Views.Grid.GridView.GetRowCellRepositoryItem(Int32 rowHandle, GridColumn column) in DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CreateCellInfo(GridDataRowInfo ri, GridColumnInfoArgs columnInfo) in DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcRowCellsDrawInfo(GridDataRowInfo ri, GridColumnsInfo columnsInfo) in DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcDataRow(GridDataRowInfo ri, GridRow row, GridRow nextRow) in DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcRowsDrawInfo() in DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo.CalcGridInfo()

But I leave all column types by default and fill columns with values of typeof(string). I check FieldName for each column and check the same property name for my dynamic objects - it equals.

2.So I try another way. Try to fill my gridview by hand using AddNewRow() and SetRowCellValue() methods. But now when I don't fill GridControl.DataSource property, and just call AddNewRow() - there no changes in my gridview. I can't see row in the grid. And when I check GridView.FocusedRowHandle it returns negative value so as I understand new row didn't add to my view.

So I need help, how can I fill BandedGridView in my situation?

Upvotes: 3

Views: 2810

Answers (1)

Ceridan
Ceridan

Reputation: 2516

I've found the solution. I made a mistake when manuly generate bands and columns. I've attach columns to the bands columns collection, but didn't attach it to bandedgridview columns collection. So, when I fix this, datasource is filled succesfully.

Upvotes: 2

Related Questions