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

GridTemplateColumn change ForegroundColor/BackgroundColor if selected

Hello,
I am using GridTemplateColumns for some custom styling.
How can I react to row selection and change colors accordingly? There seems to be nothing like GridTemplateColumns.SELECTED.
Thank you
Daniel

4 Replies

SP Subburaj Pandian Veluchamy Syncfusion Team February 12, 2019 12:57 PM UTC

Hi Daniel, 
 
Thank you for contacting Syncfusion support. 
 
Currently, we are analyzing on query with DataGrid Column template selection in Xamarin.Forms. We will validate and let you the details in one business day (February 13, 2019). We appreciate your patience until then.  
 
Regards,
Subburaj Pandian V  
 



SP Subburaj Pandian Veluchamy Syncfusion Team February 13, 2019 12:32 PM UTC

Hi Daniel, 
  
Thank you for your patience. 
  
We have checked and you can achieve your requirement of “How to react to Template column when the row selection is changed” using dataGrid selection changed event. Please refer the following code example for your reference, 
  
[C#] 
private void DataGrid_SelectionChanged(object sender, Syncfusion.SfDataGrid.XForms.GridSelectionChangedEventArgs e) 
{ 
    if(e.AddedItems.Count != 0) 
    { 
        // TempalteColor is binding property of template view. 
        (e.AddedItems[0] as OrderInfo).TempalteColor = Color.Green; 
    } 
  
    if (e.RemovedItems.Count != 0) 
    { 
        (e.RemovedItems[0] as OrderInfo).TempalteColor = Color.Red; 
    } 
} 
  
[XAML] 
<sfgrid:GridTemplateColumn MappingName="OrderID"> 
                    <sfgrid:GridTemplateColumn.CellTemplate> 
                        <DataTemplate> 
                            <Label Text="{Binding OrderID}" BackgroundColor="{Binding TempalteColor}"/> 
                        </DataTemplate> 
  
                    </sfgrid:GridTemplateColumn.CellTemplate> 
</sfgrid:GridTemplateColumn> 
  
We have also prepared the sample for your reference and attached in following link. 
  
  
We hope that this will helps you, kindly revert us if you have any concern.  
 
Regards,
Subburaj Pandian V 
 
 



UN Unknown Syncfusion Team February 17, 2019 12:43 PM UTC

Hello,

thank you for the solution.
I just switched the order of the AddedItems and RemovedItem if statements.
Otherwise clicking on an already selected row does not work as expected.

Kind regards
Daniel 


SP Subburaj Pandian Veluchamy Syncfusion Team February 18, 2019 06:05 AM UTC

 
Hi Daniel, 
 
Thank you for the update. We are happy that you have meet your requirement. 
 
Please let us know, if you need any further assistance.  
 
Regards,
Subburaj Pandian V  
 
 


Loader.
Live Chat Icon For mobile
Up arrow icon