Hi,
I would like to create a datagrid from a 2-dimensional array of a class called "GenericAttribute" containing values for the attribute key and value (example below). I'd like to map the attribute names to the column header and then each cell would show the corresponding row values. Is this possible? I tried binding against my Attributes property and I see a single row with the counts in each row so I feel like it may be possible, but I can't figure out what bindings I need for the header to work.
Since the rows are each made up of the same set of data, the first row's AttNames can be bound to the header.
thanks!
public class GenericAttribute
{
public string AttName { get; set; }
public object AttValue { get; set; }
}
private ObservableCollection<ObservableCollection<GenericAttribute>> attributes;
public Generic2dViewModel()
{
attributes = new ObservableCollection<ObservableCollection<GenericAttribute>>();
ObservableCollection<GenericAttribute> row1 = new ObservableCollection<GenericAttribute>();
row1.Add(new GenericAttribute() { AttName = "col1", AttValue = "row1Col1Value" });
row1.Add(new GenericAttribute() { AttName = "col2", AttValue = "row1Col2Value" });
row1.Add(new GenericAttribute() { AttName = "col3", AttValue = "row1Col3Value" });
row1.Add(new GenericAttribute() { AttName = "col4", AttValue = "row1Col4Value" });
attributes.Add(row1);
ObservableCollection<GenericAttribute> row2 = new ObservableCollection<GenericAttribute>();
row2.Add(new GenericAttribute() { AttName = "col1", AttValue = "row2Col1Value" });
row2.Add(new GenericAttribute() { AttName = "col2", AttValue = "row2Col2Value" });
row2.Add(new GenericAttribute() { AttName = "col3", AttValue = "row2Col3Value" });
row2.Add(new GenericAttribute() { AttName = "col4", AttValue = "row2Col4Value" });
attributes.Add(row2);
ObservableCollection<GenericAttribute> row3 = new ObservableCollection<GenericAttribute>();
row3.Add(new GenericAttribute() { AttName = "col1", AttValue = "row3Col1Value" });
row3.Add(new GenericAttribute() { AttName = "col2", AttValue = "row3Col2Value" });
row3.Add(new GenericAttribute() { AttName = "col3", AttValue = "row3Col3Value" });
row3.Add(new GenericAttribute() { AttName = "col4", AttValue = "row3Col4Value" });
attributes.Add(row3);
}
public ObservableCollection<ObservableCollection<GenericAttribute>> Attributes
{
get { return attributes; }
}