Column not frozen when binding items and columns

Dear Support Team,

I have a DataGrid and bind Columns and Items dynamically with my ViewModel. The rendering is fine appart from the fact that the first column is not frozen (interestingly it is frozen when I change something in the XAML and hot-reload fires).

My second question ist how could I set a background color for the header row and the first column?

Thank you for your support.

XAML:
<sfGrid:SfDataGrid x:Name="dataGrid" 
     VerticalOptions="FillAndExpand"
     HorizontalOptions="FillAndExpand"
     BackgroundColor="LightSeaGreen"
     AutoGenerateColumns="False"
     AutoGenerateColumnsMode="None"
     VerticalOverScrollMode="None"
     ItemsSource="{Binding DataCollection, Mode=OneWay}"
     Columns="{Binding GridColumns, Mode=OneWay}"
     FrozenColumnsCount="1">
</sfGrid:SfDataGrid>

ViewModel:
     Columns gridColumns;
     ObservableCollection<SfTableDataRow> dataCollection;

     public StatsPageViewModel(int pChapterId)
     {
          gridColumns = new Columns();
          DataCollection = new ObservableCollection<SfTableDataRow>();

          loadInitData(pChapterId);
     }

     public ObservableCollection<SfTableDataRow> DataCollection
     {
          get => dataCollection;
          set
          {
               if (dataCollection == value) { return; }
               dataCollection = value;
               OnPropertyChanged(nameof(DataCollection));
          }
     }

     public Columns GridColumns
     {
          get => gridColumns;
          set
          {
               if (gridColumns == value) { return; }
               gridColumns = value;
               OnPropertyChanged(nameof(GridColumns));
          }
     }

     private async void loadInitData(int pChapterId)
     {
          gridColumns.Add(new GridTextColumn() { MappingName = "data[0]", 
               HeaderText = "1960", 
               Width = 150, 
               HeaderTextAlignment = TextAlignment.Center,
               TextAlignment = TextAlignment.Start });
          gridColumns.Add(new GridTextColumn() { MappingName = "data[1]", HeaderText = "1961" });
          gridColumns.Add(new GridTextColumn() { MappingName = "data[2]", HeaderText = "1962" });
          gridColumns.Add(new GridTextColumn() { MappingName = "data[3]", HeaderText = "1963" });
          gridColumns.Add(new GridTextColumn() { MappingName = "data[4]", HeaderText = "1964" });
          gridColumns.Add(new GridTextColumn() { MappingName = "data[5]", HeaderText = "1965" });
          gridColumns.Add(new GridTextColumn() { MappingName = "data[6]", HeaderText = "1966" });
          gridColumns.Add(new GridTextColumn() { MappingName = "data[7]", HeaderText = "1967" });
          gridColumns.Add(new GridTextColumn() { MappingName = "data[8]", HeaderText = "1968" });

          SfTableDataRow list1 = new SfTableDataRow(new string[] { "11", "12", "13", "14", "15", "16", "17", "18", "19" });
          SfTableDataRow list2 = new SfTableDataRow(new string[] { "21", "22", "23", "24", "25", "26", "27", "28", "29" });
          SfTableDataRow list3 = new SfTableDataRow(new string[] { "31", "32", "33", "34", "35", "36", "37", "38", "39" });
          SfTableDataRow list4 = new SfTableDataRow(new string[] { "41", "42", "43", "44", "45", "46", "47", "48", "49" });

          dataCollection.Add(list1);
          dataCollection.Add(list2);
          dataCollection.Add(list3);
          dataCollection.Add(list4);

          OnPropertyChanged(nameof(GridColumns));
          OnPropertyChanged(nameof(DataCollection));
     }

1 Reply

PK Pradeep Kumar Balakrishnan Syncfusion Team April 22, 2020 09:17 PM UTC

Hi  Roland Kammerer, 
 
Thank you for contacting Syncfusion support. 
 
We have checked the mentioned issue “DataGrid column is not frozen when we generate datagrid columns dynamically” in Xamarin.Forms. Unfortunately, we couldn’t able to reproduce the issue. We have prepared a sample for your reference. Please download it from the below link.  
  
Sample Link: https://www.syncfusion.com/downloads/support/forum/153511/ze/Frozen1980969288
 
Can you please let us know whether the issue reproduces in our also? If yes, please share the details of the tested device. Else, please modify our sample to replicate the issue and revert us back with replication procedure 
 
Kindly check the sample, If the sample doesn’t meet your requirement, kindly modify the sample based on your scenario and revert us back with more details. It will be helpful for us to check on it and provide you the solution.  
 
We have also changed background color of the header row and first column in the attached sample. 
 
UG link to update style for particular cells: 
 
UG link to update DataGrid style: 
 
Regards, 
Pradeep Kumar B 


Loader.
Up arrow icon