3

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?

Marko Juvančič
  • 5,792
  • 1
  • 25
  • 41
cpVariyani
  • 159
  • 1
  • 2
  • 12
  • Duplicate of [this](http://stackoverflow.com/questions/26933083/devexpress-wpf-gridcontrol-with-dynamic-columns-and-rows?rq=1) question. – nempoBu4 Dec 30 '14 at 05:38
  • I couldn't find any good example. They all use observable collection of a custom class with a fixed number of fields. What if you have a dynamic number of columns? if you use ObservableCollection> it doesn't work. Did you ever find a solution to this ? I also need two way binding with the data. – rollsch Nov 20 '16 at 08:28

1 Answers1

1

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