Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
400
XamCalculationManager bug with custom formulas?
posted

Hello,

I am using Infragistics 12.1 release 2107.  I am having a problem getting an unboundfield with a formula to update when the cells referenced in the formula are updated.  My cell values are nullable decimals and I do not use the native multiply and subtract operators in the formula because they assume a null calculation value is 0 instead of null when a bound decimal? property value is null.  I had to write my own custom formulas for mutliply and subtract that use decimal? null instead of 0 when a calculation value is null.  My object that I am binding the XamDataGrid is an ObservableCollection of lets say Foo.  Foo has the following public properties:

FutureMarketData FutureMarketData
decimal? BidPrice
decimal? ConversionFactor

Bound Fields:

BidPrice
ConversionFactor

Unbound fields

Basis with FieldCalculationSettings Formula=="decmultiply( 32, subtract( [BidPrice], decmultiply( [FuturePrice], [ConversionFactor] ) ) )"
FuturePrice with BindingPath=FutureMarketData.LastPrice

My object Foo implements INotifyPropertyChanged and issues and raises the property changed event whenever a property changes.  FutureMarketData also implements INotifyPropertyChanged and raises the property changed event whenever a property changes.

The unbound column in the XamDataGrid sometimes has a null value even though the bound and unbound fields in the row all have values.  If I change the formula to be "decmultiply( 32, subtract( [BidPrice], [FuturePrice] * [ConversionFactor] ) )" then the Basis column will not be null however the value in Basis will be wrong because [FuturePrice] * [ConversionFactor] will be 0 even if FuturePrice is null.

When I push a button, I retrieve the future market data and the following property changed events are raised in the following order for one of my objects whose Basis cell value is null even though the bound and unbound cells used in the formula are not null:

If the notify property changed events are raised in this order then the Basis column will have a non-null value:

BidPrice
subtract is called with arguments 99.9296875 and null as expected, returning null
ConversionFactor (value is 0.9016 when notified) - FutureMarketData.LastPrice has a value at this time but event for FutureMarketData has not been raised yet
decmultiply is called
FutureMarketData (FutureMarketData.LastPrice is 110.171875 when notified)
decmultiply or subtract is never called again for this row

After this is done.  The BidPrice, FuturePrice, and ConversionFactor cells all have values shown but the Basis cell is null.

But if I raise the events in this order then the Basis cell will have a good value - not null.

BidPrice
subtract is called
FutureMarketData
decmultiply is called
ConversionFactor
decmultiply is called
subtract is called
decmultiply is called to return the final value

Why does the order the notify events are raised determine whether the cell is properly updated or not.  If the decmultiply function call is using unbound field FutureMarketData.LastPrice and  bound field ConversionFactor, then it should be called every time the following notify property changes are raised:

FutureMarketData
LastPrice on object FutureMarketData
ConversionFactor

in any order called but this does not seem to be the case.  I have attached a file with the Function_Subtract and Function_DecimalMultiply custom functions.  ToNullableDecimal is an extension method which does as you might expect, returning true when the CalculationValue is a decimal or null.



 

 

<igDP:UnboundField Name="Basis" Label="{Binding BasisLabel, Source={StaticResource BondViewModel}, Mode=OneWay}" DisallowModificationViaClipboard

="True" >

<igDP:UnboundField.CalculationSettings

>

<igDP:FieldCalculationSettings Formula

="decmultiply( 32, subtract( [BidPrice], decmultiply( [FuturePrice], [ConversionFactor] ) ) )" />

<!--<igDP:FieldCalculationSettings Formula="decmultiply(32,subtract([BidPrice],[FuturePrice] * [ConversionFactor]))" TreatAsTypeName="Nullable&lt;Decimal&gt;" />-->

</igDP:UnboundField.CalculationSettings

>

<igDP:UnboundField.Settings

>

<igDP:FieldSettings EditorType="{x:Type igEditors:XamNumericEditor}" EditorStyle="{StaticResource BasisFormat

}" />

</igDP:UnboundField.Settings

>

</igDP:UnboundField

>