Dynamic dataset binding not working

I'm having problems with binding to a data grid.  I've got a dynamic data set, so I can't just create objects.  I've tried using both an array of ExpandoObjects and a DataTable, the result is the same.  If I explicitly create the dataset, it works but this doesn't do me any good.  My xaml is:
     <sf:SfDataGrid BackgroundColor="{ DynamicResource DataGridHeaderRowBackgroundColor }" ItemsSource="{Binding TableData, Mode=OneWay}" Columns="{Binding Columns, Mode=OneWay}" AutoGenerateColumns="False"></sf:SfDataGrid>

For example:
int cellIndex = 0;
foreach (TableCell cell in row.Cells.OrderBy(c => c.ColumnIndex))
{
    GridTextColumn column = new GridTextColumn
    {
        HeaderText = cell.CellText
    };

    if (cell.CellType == TableCellType.Checkbox)
    {
        column.ColumnSizer = ColumnSizer.SizeToHeader;
    }
    else
    {
        column.Width = 200;
    }

    column.MappingName = cellIndex.ToString();
    column.HeaderFontAttribute = FontAttributes.Bold;
    column.HeaderTextAlignment = TextAlignment.Center;
    column.HeaderFont = "SourceSansPro-Bold.ttf#Source Sans Pro";
    column.HeaderCellTextSize = 14;
    column.LoadUIView = true;
    column.LineBreakMode = LineBreakMode.CharacterWrap;

    this.Columns.Add(column);
    cellIndex++;
}

Dictionary<string, object> s = new Dictionary<string, object>();
s.Add("0", "zero");
s.Add("1", "one");
s.Add("2", "two");
s.Add("4", "three");
s.Add("5", "four");
s.Add("6", "five");
s.Add("7", "six");
s.Add("8", "seven");
s.Add("8", "eight");
tableData.Add(s.ToExpando());

this.TableData = tableData;

Now, for my real data I do this (column stuff is exactly the same).  This does not work, I get the attached screenshot.

Dictionary<string, object> rowData = new Dictionary<string, object>();
int cellIndex = 0;
foreach (TableCell cell in row.Cells.OrderBy(c => c.ColumnIndex))
{
rowData.Add(cellIndex.ToString(), string.IsNullOrEmpty(cell.CellText) ? "EMPTY" : cell.CellText);
cellIndex++;
}

tableData.Add(rowData.ToExpando());




4 Replies

PK Pradeep Kumar Balakrishnan Syncfusion Team June 22, 2020 05:49 PM UTC

Hi Nick, 
 
Thank you for contacting Syncfusion support.  
 
Currently, We are checking on the reported issue ”Dynamic binding is not working in DataGrid”. We will validate and update you the details by June 24, 2020. We appreciate your patience until then.    
 
Regards, 
Pradeep Kumar B 



PK Pradeep Kumar Balakrishnan Syncfusion Team June 24, 2020 05:33 AM UTC

HI Nick,  
  
Thank you for your patience.  
  
We have checked the shared code snippet and the reported issue Dynamic binding is not working in DataGrid in xamarin forms. you have defined LoadUIView for column as true change it false so the text will be rendered for Android platform alone.  
   
For your information.  
  
In Xamarin.Forms Android only, we are drawing the text for better performance, so that the view will rendered. If we load Label for the same scenario by setting LoadUIView as true for all of the column, then you will face rendering issue “Cell value doesl not render” in all the platform it is because Xamarin forms have not yet given binding support to the Expando object.  
   
In Xamarin forms ExpandoObject binding is under implementation.  
  
Please refer the following link for more details regarding IOS platform limitation for Dynamic object.  
  
We suggest you to use ObservableCollection<Model class> or DataTable collection as SfDataGrid Itemsource.until Expando object binding support is provided by xamarin forms framework.  
  
Regards,  
Pradeep Kumar B  



NI Nick June 25, 2020 02:39 PM UTC

I'm confused.  The first example uses and ExpandoObject and that solution works just fine.  There has to be something else going on here.  If I change the xaml while the application is running the grid seems to render after it reloads.


PK Pradeep Kumar Balakrishnan Syncfusion Team June 26, 2020 05:24 PM UTC

Hi Nick, 
 
Thank you for the update. 
 
Query 1: provided solution just worked for me. 
 
Yes, it will work for Android platform alone. Because In Xamarin.Forms Android only, we are drawing the text for better performance in LoadUI false case, so that the view will rendered and same solution will not work for xamarin forms IOS, Xamarin forms UWP, Xamarin forms WPF and Xamarin forms MacOs platform. 
 
Query 2:  If I change the xaml while the application is running the grid seems to render after it reloads. 
 
Please share in which platform while changing Xaml code Expando object binding is worked in your application also what changes you made in XAML and share your application Xamarin forms version to check the reported behaviour on our side. 
 
Regards, 
Pradeep Kumar B  

Loader.
Up arrow icon