Hi there
We are using v12.1.20121.2038 of the UltraWinCalcManager in combination which the UltraWinGrid
I would like to display the FormulaBuilderDialog for a cell via a right click context menu item and have the formula effect a single UltraGridCell only rather than the entire UltraGridColumn or a SummaryColumn, which is what the Formula Builder At RunTime sample does.
Am I correct in thinking that because the UltraGridCell does not implement the IFormulaProvider interface that it cannot be done?
Is there a workaround via another property/object related to the UltraGridCell?
Is this possible and if so how? Do you have any samples?
Regards
geoffhop
Hi,
No, this is not possible. You cannot apply a formula to an individual grid cell. The grid only supports formulas on a column or a summary, not on a cell.
Hi Mike
Thanks for that
Would you have any suggestions for an alternative from your suite of WinForms controls?
Essentially I want the user to be allowed to enter a numeric formula that will be applied to an individual cell only
geoffhop said:Do you have an example/sample of hooking up the FormulaBuilderDialog to an UltraTextEditor?
Hm... I don't have a sample of this off-hand, but it should be pretty easy. It's very similar to the way you do it in the grid. The grid sample has a method called ShowFormulaBuilderDialog which takes in a FormulaProvider. So you can use the same method, it's just a question of getting the FormulaProvider for the UltraTextEditor. For any simple control like this, you could use the CalcSettings, which you can get from the UltraCalcManager.
CalcSettings calcSettings = this.ultraCalcManager1.GetCalcSettings(this.ultraTextEditor1); this.ShowFormulaBuilderDialog(calcSettings);
geoffhop said:Do you think it would be feasible to to somehow manipulate a hidden UltraTextEditor that is hooked upto a FormulaBuilderDialog with the value of the Text box just pointing to the value of an UltraGridCell?
It might be feasible, but there are a couple of issues you would have to work out.
I'm not sure if the CalcManager looks at the Visibility of a control. I don't think it does, but if I am wrong, you might have to hide the control by positioning it off-screen instead of setting Visible to false.
Then you would have to handle copying the value from the UltraTextEditor into the grid cell. So I suppose you could just trap the TextChanged property for that.
Thanks Mike
I will look into that. As a workaround I have added a hidden unbound column to the grid which is used to provide the interface to the FormulaBuilderDialog, the calculated formula is then copied from this hidden column to the cell I actually want to display the result it. Not the most efficient thing ever but it works and I will never have more than 120 rows in the grid so I can wear the overhead. But your thought on the UltraTextEditor may provide a more efficient technique so I will give it a try.
Thanks again
I'm confused. How are you applying the formula to the cell? The grid does not support that.
Are you saying that you just want the user to build a formula and then have the cell simply display the text of that formula in the cell? If so, then I missed that in your original post.
If that's what you want then using a hidden column is not a bad idea. But I think using a hidden TextBox would be more efficient, since it would only require one calculation instead of one for every row. But as you said, if you only have 120 rows, it doesn't matter that much. And you could read the formula out of the column and then immediately clear it out, also.
Yeah my requirement is for each cell in a column to have a value calculated for it from a formula but with each cell using a different formula. This is where the hidden column "bound" to a formula come's in. The hidden column has the formula applied to it using the FormulaBuilderDialog with the result of the formula's calculation then transposed to a single cell in my real column.
Your right the hidden text box would be more efficient which is why I asked about it and will be attempting to use.
Oh, I see. So you are going to have an unbound column for each formula? So that means potentially a column for every row in the grid?
That could get pretty inefficient, even with only 120 rows. I recommend that you test it out with 120 different formulas just to make sure it's going to be performant.
Yeah that's right. Got it working with the hidden UltraTextEditor now so the hidden column in the grid strategy is now redundant.
Thanks a lot for your help
Oh, I see. So the thing I was missing is that these calculations are one-shot. Normally, the CalcManager calculates continuously and updates as values are changed on the fly. But you are only doing them once. That makes sense now.
Not quite. Only 1 unbound column and 2 bound columns per row, The unbound column is the one the FormulaBuilderDialog is hooked to, the unbound column is invisible and will effectively have the same value for each row, i.e for a raw formula of 2+2 each cel in each rowl in this column would have a value of 4.
The 2 bound columns are the displayed to the user.
The first is the value of the last formula, not the calculated result just the raw formula string i.e. 2+2 but the cells value is only set when it is the row which has focus when the FormulaBuilderDialog is displayed, all other rows are NOT updated with the formula in this bound column only the current row. Each cell in the column will have a different raw formula string value.
The second bound column is the calculated result of the last formula i.e. for a formula of 2+2 the cell's value is 4. The cells' value is only set when it is the row which has focus when the FormulaBuilderDialog is displayed. Each cell in the column will have a different calculate formula result.
A right click context menu item on cell is used to provide a menu to display the FormulaBuilderDialog and I grab the raw formula string from the cell in first bound column of the CURRENT row and give to the FormulaBuilderDialog to use to display as the current formula.
Hope that makes sense!