简体   繁体   中英

DevExpress GridControl with dynamic columns and rows

I'm working with a DevExpress 14.1 GridControl on WPF, which must bind to a dynamic source. We don't know the number of columns or rows on design time, so this must be calculated on the fly.

The source may be changed while executing, adding more rows, or columns, or BOTH (I could have a table with 3 columns and 5 rows, and a 6th row with 4 columns could be inserted, adding a new column to the model with empty data for the previous rows).

I was using a DataTable as ItemsSource for the grid, but it will only load data inserted on design time. If I add columns while running the app, the grid wont update for some reason.

Is there an observable object that can satisfy this needs?

The dynamic columns must be created and added to the GridColumncollection programmatically on the fly. They must be unbound .

GridColumn.FieldName Set this property to a unique string that does not match any field name in the grid control's underlying data source.

GridColumn.UnboundType Set this property to a value that identifies the type of data the column is supposed to display (Boolean, DateTime, Decimal, Integer, String or Object).

To check how GridColumns are created and added see your generated file.

There is a grid event to handle the unbound cells data set and get (It's one event doing both): ColumnView.CustomUnboundColumnData

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM