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

How to set MaxValue of a GridNumericColumn to a dynamic value

I have a data grid with (amongst others) a numeric column. Each or it's rows has been bound to an instance of a LevelDataRow using the grid's ItemsSource property. The column's column mapping has been bound to a property called Spill. So the column definition currently looks like this:-
xaml Code:
  1. <sf:GridNumericColumn HeaderText="Spill (Ml/d)" AllowEditing="True" NumberDecimalDigits="2" MappingName="Spill" CellStyle="{StaticResource SpillCellStyle}" MinValue="0" MaxValue="9999"/>


The thing is the Max value should not be a static value of 9999. It needs to be a dynamic value calculated for each Row. A simple property to calculate the MaxValue would like this:-
C# Code:
  1. public double MaxSpill { get { return Volume - m_reservoirWrapper.Capacity; } }

I can't seem to work out how use that function to set the MaxValue on the column. Something a bit like this:-
xaml Code:
  1. <sf:GridNumericColumn HeaderText="Spill (Ml/d)" AllowEditing="True" NumberDecimalDigits="2" MappingName="Spill" CellStyle="{StaticResource SpillCellStyle}" MinValue="0" MaxValue="{Binding Path=MaxSpill, Mode=OneWay}"/>


Any suggestions?

4 Replies

SA Saravanan Ayyanar Syncfusion Team December 19, 2019 01:39 PM UTC

Hi Declan Hillier, 

Thank you for using Syncfusion control. 


We have prepared the sample based on your requirement. You  can able to bind the different MaxValue in each row of GridNumericColumn. Here you should override the class GridNumericCellRenderer and GridNumericColumn

Please find the sample link below 

Sample Link: 



Please let us know, if you require further assistance on this. 

Regards, 
Saravanan A. 



DH Declan Hillier December 19, 2019 02:12 PM UTC

Thank you.  This is tremendously helpful.


DH Declan Hillier December 19, 2019 02:58 PM UTC

I'm working my way through the code and believe I mostly understand it.

However, I get an error when I try to run it.  I change a value in a cell and this line of code:-
"customColumn.MaxValue = customColumn.MaxValueSelector.GetMaxValue(dataContext);"
...in GridCellNumericRendererExt.OnInitializeEditElement is throwing the following error:-
"Unable to cast object of type 'Syncfusion.UI.Xaml.Grid.GridCell' to type 'System.Windows.Controls.TextBlock"



SA Saravanan Ayyanar Syncfusion Team December 20, 2019 10:47 AM UTC

Hi Declan Hillier, 
 
We have analyzed your query related the following error “Unable to cast object of the type Syncfusion.UI.Xaml.Grid.GridCell to type System.Windows.Controls.TextBlock” but the issue not reproduced its works at our end. So could you please check the below video location. 
 
Sample Video Link: 
 
 
 
If still you are facing the same issue, please revert us with more details on replication/video illustration of the issue. Also if possible, please revert us with the modified sample. It will helps us to investigate further and provide earlier prompt solution. 
 
Please let us know, if you require further assistance on this. 
 
Regards, 
Saravanan A. 


Loader.
Live Chat Icon For mobile
Up arrow icon