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.
Unfortunately, activation email could not send to your email. Please try again.

SfDataGrid Conditional Styles on Property changed

Thread ID:

Created:

Updated:

Platform:

Replies:

131724 Jul 25,2017 08:06 AM Jul 28,2017 07:35 AM Xamarin.Forms 3
loading
Tags: SfDataGrid
Christopher Schulze
Asked On July 25, 2017 08:06 AM

Hi,

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.
Thanks
Christopher

Ashok N [Syncfusion]
Replied On July 26, 2017 03:38 PM

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.  
 
Regards, 
Ashok 


Christopher Schulze
Replied On July 27, 2017 12:00 PM

Hi,

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.

Greetings

Christopher


Ashok N [Syncfusion]
Replied On July 28, 2017 07:35 AM

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   
   
Regards,   
Ashok   


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;