Dynamic Compute Column
FeaturedHi,
I want to add dynamic Computation columns in the grid, refer the attached sample code
in that i want to add a Computation column when the click of "Add Computation Colum 1" that dynamic Computation column should calculate the value of "Price+Qty" when ever the grid got update the calculation value needs to be changed basen on the expression,
also i want to create the amother one dynamic Computation column in the button click of "Add Computation Colum 2" it should calculate the value of "Price-Qty"
all expression are will changed in dynamically or through config file, means "Price+Qty" may change "Price/Qty" also "Price-Qty" may
change "Price*Qty"
how can i achive this feature in the grid.
Regards,
Sasee G
DapForDynamicComputationColumn.zip
-
Hi,
This is a really easy with the .Net Grid and can be done in 2 lines of code. The main idea is to join properties of different objects. You’ve already the MyData class which implements the INotifyPropertyChanged interface. Very good! We should just add a field UnboundValueAccessor to this class and corresponding get-property. Let’s call it DynamicFields. Then you have to decorate this property with the CompositeFieldAttribute. UnboundValueAccessor represents a kind of dictionary with variable number of fields. Look at the following example:
class MyData : INotifyPropertyChanged
{
private readonly UnboundValueAccessor _dynamicFields = new UnboundValueAccessor();
...
[Field("Price")]
public int Price
{
get { return _Price; }
set
{
_Price = value; Notify("Price");
_dynamicFields["Field1"].Value = _Price*_Qty;
}
}
...
[CompositeField]
public UnboundValueAccessor DynamicFields
{
get { return _dynamicFields; }
}
}Objects of this class are able to notify the grid each time when a setter is called. Finally, you should add columns with field identifiers that match to fields of the UnboundValueAccessor. A good practice will be to set an appropriate formats in that columns. Please find an attached example, demonstrating this approach.
Best regards,
Dapfor
DapForDynamicComputationColumn.zip
DynamicFields.png0 -
This doesn't works for us, as we need the formula for the dynamic column needs to given dynamically by the end user. So can you suggest us how .NET grid can be used for this facility.
0
Please sign in to leave a comment.
Comments
2 comments