We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Binding 2dimensional array to DataGrid

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; }
        }

1 Reply

SV Srinivasan Vasu Syncfusion Team May 18, 2016 02:06 PM UTC

Hi Deanna, 
 
We have prepared a sample as per your scenario and the SfDataGrid does not support for the reported collection. Hence the support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.  
 
 
Regards, 
Srinivasan 
  
 


Loader.
Live Chat Icon For mobile
Up arrow icon