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 Conditional Styles on Property changed


I tried out the Conditional Styles  on sfDataGrid.
My model has 3 important properties:
- value: The Value that should be changed by Grid editing
- warnLevel: Is the entered Value higher the cell style on value (GridNumericColumn) should change, e.g.: the BackgroundColor should be orange
- maxLavel: Is the entered Value higher the cell style should change BackgroundColor to red for example

I created a IValueConverter doing this and attached it. It is working only for initial values.

My initial value is 0 because the user must enter one. After entering the value the style should be applied, but nothing happend.

Is there any solution to get this working. I've tried some strange things with Triggers, but nothing worked.
I'm heavily using MVVM, but if there is an solution for updating the grid in codebehind I'm able to trigger an event for that from the view model.

Hopefully everybody has a solution.

3 Replies

AN Ashok N Syncfusion Team July 26, 2017 07:38 PM UTC

Hi Christopher 
Thanks for contacting Syncfusion support. 
You can achieve your requirement by handling CurrentCellEndEdit event. Using reflection you can get the DataColumnBase and set ((DataColumnBase as IElement).Element as GridCell).NeedToInvalidate = true. Please refer the below code example  
dataGrid.CurrentCellEndEdit += DataGrid_CurrentCellEndEdit; 
private void DataGrid_CurrentCellEndEdit(object sender, GridCurrentCellEndEditEventArgs args) 
    var row = this.dataGrid.GetRowGenerator().Items.FirstOrDefault(x=>x.RowIndex == args.RowColumnIndex.RowIndex); 
    List<DataColumnBase> columnCollection = row.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "VisibleColumns").GetValue(row) as List<DataColumnBase>; 
    var column = columnCollection.FirstOrDefault(col => col.GridColumn == dataGrid.Columns[args.RowColumnIndex.ColumnIndex]); 
    if (column != null) 
        ((column as IElement).Element as GridCell).NeedToInvalidate = true; 
Note: You want to set the LoadUIView as true for condition style applied column.  

CS Christopher Schulze July 27, 2017 04:00 PM UTC


at first: thanks for your fast reply.

This solution is only partially working. I need to check for two properties naming "warning" and "maximum" of my model in the ValueConverter. I tried to bind the whole Object with {Binding Path=., Converter... The Converter gets the whole object in OnAppearing , but is no more called in OnCurrentCellEndEdit. Calling the Converter is only working when I bind to my "Value" (StudentMarks in your Sample) Property.

I also tried a few things of passing the warning and maximum as Converter Parameters, but without success. Style.DataTrigger also didn't work.

I also found a possible bug in your sample: when I change the "sfgrid:GridTextColumn" to "sfgrid:GridNumericColumn" (I need a Numeric Column in my case) the BackroundColor is changing but the Text isn't visible anymore. Transforming your sample solution to my current project the text is not missing.

So finally I need a way to pass two additional properties of my model (or the whole model) to the converter.



AN Ashok N Syncfusion Team July 28, 2017 11:35 AM UTC

Hi Christopher,   
A support incident has been created under your account to track the status of this. Please log on to our support website to check for further updates   

Live Chat Icon For mobile
Up arrow icon