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

sfdatagrid with unknown number of columns in design time

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

3 Replies

SP Subburaj Pandian Veluchamy Syncfusion Team 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 



IL Ilya 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


SP Subburaj Pandian Veluchamy Syncfusion Team 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 


Loader.
Live Chat Icon For mobile
Up arrow icon