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.
Unfortunately, activation email could not send to your email. Please try again.

Binding 2dimensional array to DataGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

124106 May 17,2016 01:33 PM May 18,2016 10:06 AM UWP 1
loading
Tags: SfDataGrid
Deanna Delapasse
Asked On May 17, 2016 01:33 PM

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

Srinivasan Vasu [Syncfusion]
Replied On May 18, 2016 10:06 AM

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 
  
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;