title: Silverlight DataGrid - Binding to a Collection of Collections of objects
body: <p>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. The datagrid cell will be either a string or a value changeable via a combobox.</p>
  
  <p>Attempted 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. </p>
  
  <p>My solution as a result has been to display the data in a more traditional manner, with a list and a datagrid. When you select an item in the list it repopulates the data in the datagrid to show the objects. </p>
  
  <p>Question: is there a way to bind a datagrid cell to a collection of collections of objects?</p>
  
  <p>I found this question (WPF) which looks similar and it didn't help any. I think it's the same issue.
  <a href="https://stackoverflow.com/questions/1633800/wpf-datagrid-datagridcomboxbox-itemssource-binding-to-a-collection-of-collection">WPF DataGrid: DataGridComboxBox ItemsSource Binding to a Collection of Collections</a></p>