Hello Team,
We want to calculate the values at run-time manually. The formulas are not fixed, the users can create the formula of their choice. Our data is as follows
Unit Value Formula
LF 10
SF 20
VL 30
R1 SQRT (LF * SF)
R2 SUM (VL , LF , SF)
The 'R1' and 'R2' are the summary or Grand Total row, the result would be displayed in the value coulmn on the basis of the Formula entered in their respective rows.
How to implement the calcManager manually at runtime for these Rows ?
We would also be using all the built-in functions provided by infragistics Formula Builder (for eg. cos,abs, average ..etc).
Looking forward to your reply.
Hi,
There's no way to apply a formula to an individual cell in the WinGrid. You can apply a formula to a Colmun or a Summary.
It seems to me that you should use a Summary here, rather than a column. Why show a whole column of empty Cells just to show two values in rows which would also have empty cells?
So what you would do is use the InitializeLayout event of the grid and use the band.Summaries.Add method to add your two summaries with formulas.
Thank you for the reply.
As per our example in the R1 and R2 rows, the value column will have the result on the basis of the formula provided againt these respective rows. As we are allowing the user to make the formula, the number of rows in which the user can select the formula is not fixed, and also the formula will contain the combinations of any rows.
Is there any other way we can do it ? We cannot apply summary as it is applied to the column and not the cell and also the number of rows in which the user would have defined the formula is not fixed.
Looking forward for your reply.
Oh, I see what you mean.
As I said, you cannot apply a formula to a single cell in the grid. You could use a Summary or perhaps a control outside the grid, such as a TextBox or a Label.
While it is not possible to apply a formula to a single cell, you can refer to a single cell within a formula. You can only refer to a cell by index, though, not by a value in the row.You can even refer to a cell based on the value in another column.
So perhaps you could use NamedReferences to give the users a shortcut to the values you want.
For example, you could define a NamedReference called "LF" and give it a formula like so:
[//ultragrid1/Band 0(Unit="LF")/Value]
This will give you the value of the Value column in Band 0 where the Unit Value is "LF".
As it is not possible to set a formula rowwise (on a single cell), we thought of a workaround for it. We are dispalying the formulas column wise i.e. our Data would be as follow
LEN WID HGT F1
10 20 30 (2*LEN*HGT)+(2*WID*HGT) + (LEN*WID)
We will have only one row in a grid. the Units would be displayed in the columns. The user will edit the values in 'LEN','WID' and 'HGT' column and 'F1' will have a formula.
We have to set the formula to the F1 column at the run time. How to assign the formula to the column at the run time. We can have more than one formula coulmns. We retirve the data in the dataset and willl have to go in the loop to assign the formula to the respective columns.
Can you please tell us, is there any way to assign a formula to a columns at run time ?
I'm not sure I understand the question. There is Formula property on the column and you set it to the formula you want. What part of this are you having trouble with?
I recommend using the InitializeLayout even for something like this.
e.Layout.Bands[0].Columns[F1].Formula = "(2*[LEN]*[HGT])+(2*[WID]*[HGT]) + ([LEN]*[WID])";
Thank you Mike. It did work.
We are attaching an sample application for your reference. In this we have two grids Grid 2 will be hidden. any changes made to the 'value' column of 'Grid 1' is to be reflected in the 'Grid 2' in there respective column.
When the values in the 'Grid 1' 'value' column changes, we are changing the value of its corresponding coulmn in 'Gird 2' by looping through in 'Grid 2' columns.
Is there any way to get the values of 'Grid 1' column directly to its corresponding columns in 'Grid 2' instead of looping through in the 'Grid 2' and set the value ?
As we cannot give formulas to the rows / cells we have assigned the formulas to the columns in the second (hidden) grid and the result of the second grid would be set in the rows of first grid. We know it is a little lengthy process, but we thought this is the only work around for it, provided you suggest some other better solution for it .
Looping is probably the best way to do this.
If the grids are both sorted the same way, you could use the index of the row in the second to find the row in the first grid. But then you would have the added difficulty of trying to keep the sorting in synch.
What's the point of having the second (hidden) grid, though?