Hi,
I'm trying to produce a column (results) in a dataGridView whose value is calculated from pre-existing formulas, which are located in a separate column (formulas). The formulas, and subsequently results, are different for each row, but the logic should be the same, just use the formula from the 'formula' column to calculate the value for 'result'. The formulas are currently displayed as strings, with the same format as if they had been produced by FormulaBuilder. I've so far had no luck trying to assign the formula column to the 'formula' property of an IFormulaProvider.
Is there any way to do this?
Any help is greatly appreciated!
Thanks,
Joel
Hi Joel,
Just to make sure I understand... you have a DataGridView (not an UltraWinGrid) and you have a column that contains a string which is a formula. And you want to apply that formula to a cell in the same row.
You cannot apply a formula to an individual cell. So if you are trying to get a different formula in each row based on the string in the other cell, it will not work.
But... if you want to apply a formula to a column, you would do it like this:
DataGridViewColumnCalcSettings calcSetting = this.ultraCalcManager1.GetColumnCalcSettings(resultsDataGridViewTextBoxColumn);calcSetting.Formula = "2+2";
Hi Mike,
Thanks for your reply. Yes, that's what I want to do. I was just unsure whether it was possible or not to do it. I was hoping it would be something like calcSetting.Formula = ' "= " + resultsDataGridViewTextBoxColumn', but no worries!
I'm using a DataGridView, but it would be fine to use an UltraWinGrid if this would make it possible.
So there's no way of using different formulas for different rows?
Thanks again for your reply, it's most appreciated!
No, that would not work. If you set a formula on the EditorControl, then it would only affect that Editor control, it would have no effect on the grid. Remember that a single editor control can service any number of cells. So there can be no associated between the Value on the editor control and the Value of the grid cell(s). That would not make sense, since it would force all of the cells to be the same value.
The editor control simply provides an editor for use by the grid - the grid does not use the actual control.
No, there is no way to apply a formula to a cell, you can only apply it to the entire column. So you can't vary the formula by row. This is true for both the DataGridView and the UltraWinGrid.