This week I hit a limitation in the Silverlight DataGrid control. I'm hoping it's just something I've not learned yet with bindings but it does appear that the simplest solution is to display the data in a different manner.
Problem: The data I'm trying to display is essentially a collection of collections of some object. So the rows can be any number, normal for a datagrid, and the columns are also any number. That's not so normal for a datagrid. Usually you have a set number of columns and your rows vary.
Solution: I tried adding columns to the datagrid dynamically, and while this worked just fine (adding them in codebehind) the real issue I hit was how to bind to the underlaying objects. The data is being built dynamically and I tried a couple of formats. I tried a collection of Arrays, and also an ObservableCollection of ObservableCollections. I could bind to the objects but as Bindings in Silverlight have to bind to properties I couldn't come up with a solution presenting the data this way.
My solution as a result has been to display the data in a more traditional manner, with a lists and a datagrid. When you select an item in the list it repopulates the data in the datagrid to show the objects.
If anyone comes across a way to bind a datagrid cell to a collection of collections please let me know.
Friday, January 8, 2010
Subscribe to:
Posts (Atom)
