Say I have an ObservableCollection (type MyRow) (called Rows) of rows. In MyRow I have a bunch of properties, including an ObservableCollection (type MyRowContents) (called Contents) - which is basically a list of all of the contents that will be in that row. MyRowContents also has several properties, including DisplayContents (string).
For example... for DataGrid with 2 rows, and 3 columns the data structure would be 2 "Rows", and each would contain 3 "Contents".
What do I have to do in the DataGrid in the XAML so that the cell contents display Rows[i].Contents[j].DisplayContents?
EDIT:
Hi, sorry for not being clear enough in the initial message. I am trying to make a data grid that is capable of displaying data dynamically (from a database table that is unknown ahead of time).
I have used this as a guide: http://pjgcreations.blogspot.com.au/2012/09/wpf-mvvm-datagrid-column-collection.html - and I can display the columns dynamically.
<DataGrid ItemsSource="{Binding Rows}" AutoGenerateColumns="False"
w:DataGridExtension.Columns="{Binding ElementName=LayoutRoot, Path=DataContext.Columns}" />
I just don't know how to display the row data dynamically.
MyRow is:
public class MyRow
{
public int UniqueKey { get; set; }
public ObservableCollection<MyRowContents> Contents { get; set; }
}
MyRowContents is:
public class MyRowContents
{
public string ColumnName { get; set; } // Do I need this?
public object DisplayContents { get; set; } // What I want displayed in the grid cell
}
I have a public property ObservableCollection Rows in my view model, which as you can see is what I am binding to in the ItemsSource. But I don't know how to get the "DisplayContents" of each MyRowContents to display in the appropriate cell in the grid view.
Given that I can display the column names dynamically, this assumption can be made: the order of the items in Contents (in MyRow) will match the order of the columns.
Thanks