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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

sfdatagrid with unknown number of columns in design time

Thread ID:

Created:

Updated:

Platform:

Replies:

141665 Dec 26,2018 10:20 AM UTC Jan 3,2019 08:49 AM UTC Xamarin.Forms 3
loading
Tags: SfDataGrid
Ilya
Asked On December 26, 2018 10:20 AM UTC

Hello, 

i have class which hold product data
  public class cProductData
    {
        public int prodID = -1;
        public string Name = "";
        public decimal Cost = 0;
        public decimal Weight = 0;
        public int Calories = 0;
        public int count = 0;
//shortened here
}

i gather data here  public Dictionary<string, Dictionary<string, cProductData>> PortionsAll { get; set; }

where 
1) key in outer Dictionary is productname
2) key in the inner dictionary is date
3) value in the inner dictionary is product.weight.tostring ()

basically, i want to have a grid, where
left column cells are 1 ( productdata.name,)
toprow cells are 2 (date)
and cell value is 3 (product weight )

with standard xamarin grid i just create it programmatically 
now i am trying to use sfdatagrid and bind this structure

for the sake of simplicity i converted the above data to 
public List<List<string>>SFData { get; set; }
(also tried List<string [] > )

but i am getting columns mapped to list properties (see attached file) . what i am doing wrong  ? :)
sincerely 
ilya

Attachment: 20181226_131541_81920aaf.zip

Subburaj Pandian Veluchamy [Syncfusion]
Replied On January 2, 2019 12:14 PM UTC

Hi Erik,  
  
Thank you for contacting Syncfusion support. 
  
We have checked your query with DataGrid in Xamarin.Forms, as you mentioned we cannot set the List<List<string>> property ItemSource of the DataGrid. In SfDataGrid DataSource is an object which supports data sources such as list, ObservableCollection. While we bind the List<List<string>> column generate with properties of list, so that we cannot List<List<string>> type to ItemSource. We have prepared the sample based on your requirement and attached the sample for your reference.  
 
  
You can also refer the same by the following online user guide link, 
   
 
Please let us know, if this helpful.
  
Regards,  
Subburaj Pandian V 


Ilya
Replied On January 2, 2019 12:58 PM UTC

Thank you. 
i already did it from code with some additional dataclass

public class ProductRow
    {
           public string ProductName { get; set; }
        private Dictionary<int, string> dweight;

         public Dictionary <int, string> Test 
        {
            get => dweight;
            set => dweight = value;
        }
    }

      void CreateSfGrid()
        {

            int numcol = vm.NumDays;
            gridSf.Columns.Add(new GridTextColumn() { HeaderText = "product", MappingName = "ProductName" , ColumnSizer = ColumnSizer.Auto  });
            for (int i = 0; i < numcol ; i++)
            {
                string hdr = vm.SFRowData[0][i + 1];
                gridSf.Columns.Add(new GridTextColumn() { HeaderText = hdr, MappingName = $"Test[{i}]", ColumnSizer=ColumnSizer.Auto });
            }

            gridSf.FrozenColumnsCount = 1;
            gridSf.ItemsSource = vm.SFRowData;
}

where vm.SFRowData is 
public List<ProductRow>SFRowData { get; set; }

thank you
ish

Subburaj Pandian Veluchamy [Syncfusion]
Replied On January 3, 2019 08:49 AM UTC

Hi Ilya, 
 
Thank you for the update. We are happy that the mentioned issue has been resolved at your end.  
 
Please let us know, if you need any further assistance.  
 
Regards,
Subburaj Pandian V 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon