Set background color programmatically

Hi 

I need to set the background color programmatically of the first column (column with expander) of a SfTreeGrid

I've tried this code but it doesn't works:

MyColumn.CellStyle = new Style(typeof(TreeGridExpanderCell));

MyColumn. CellStyle.Setters.Add(new Setter(TreeGridCell.BackgroundProperty, myColor));


Thanks in advance

Miky


3 Replies

VS Vijayarasan Sivanandham Syncfusion Team July 8, 2021 03:41 PM UTC

Hi Michele,

Thank you for contacting Syncfusion Support.

Your requirement can be achieved by set the style into ExpanderCellStyle in SfTreeGrid. Please refer the below code snippet, 
private void Changes_Button_Click(object sender, RoutedEventArgs e) 
{ 
            //apply the background colur for TreeGridExpanderCell in SfTreeGrid 
            Style style = new Style(typeof(TreeGridExpanderCell)); 
            style.Setters.Add(new Setter(TreeGridExpanderCell.BackgroundProperty, Brushes.Green)); 
            treeGrid.ExpanderCellStyle = style;             
} 
Please let us know if you have any concerns in this.

Regards,
Vijayarasan S 



MI Michele July 9, 2021 09:33 AM UTC

Vijayarasan 

It works. 

I suggest to explain it also in the official documentation.


Thanks 

Best Regards,

Miky




VS Vijayarasan Sivanandham Syncfusion Team July 9, 2021 10:36 AM UTC

Hi Michele,
 
Thanks for the update.
 
We will consider your suggestion. We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.
 
Regards,
Vijayarasan S


Loader.
Up arrow icon