views:

11

answers:

1

I have two dimensional data with varying number of rows and columns and must display it to the user for editing. The format of the data itself is essentially described by a list of row and column descriptors with a header text for each row or column.

I derived a control from Grid that has two properties for the row and column descriptors and builds the gird rows and columns based on that information. It also subscribes list change events of the two descriptor collection to update itself if the user dynamically adds or removes rows or columns.

And here the problem occurs - when I try to modify the row or column definitions of the gird I get an exception telling that the collection is read-only. So I assume it is not possible to modify the definition after the grid has been created and shown once. Any ideas?

And just in the case it matters - everything is data bound. There is a (dynamic) collection of tables with each table containing its own (dynamic) row and column definitions and the data entered for each cell.

+1  A: 

I did a quick test and I could add rows and columns without problems to a Grid at runtime through code, using the RowDefinitions and ColumnDefinitions collections. I don't think that bindings have something to do with the problem either.

If on the other hand you meant DataGrid, yes, that changes things quite a bit.

Alex Paven
You are right - the collections can be modified. I received several change notifications from the modified descriptor list and the first one correctly updated the row and column definitions. The second one failed because now the collection is marked as read-only. I don't know (and haven't investigated) why it works this way but for my scenario all is fine - I just do nothing if the definitions have become read-only because all necessary changes are already done the first time. At some point after my code executed the collections become modifiable again and allow further changes to the grid.
Daniel Brückner