According to the help formulas on bound columns are supported but I can't get it to work. http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.1/CLR2.0/HTML/WinCalcManager_Formula_and_Reference_Guide.html
When I assign a formula to a bound column I get strange behaviour. When the source cell is changed via the underlying DataTable it's value displayed in the grid doesn't update - but it does redraw when the mouse hovers over the cell! But also the calculated formula value doesn't update at all. If I add an unbound column with the same formula this also doesn't update when the source cell changes. But if I remove the formula on the bound column the cell updates properly and the unbound column shows the calculated value. Note that if the user modifies the value in the cell directly then both the bound and unbound cells update correctly, so it's only when the update is through the datasource.
I really need to be able to use a bound column as I need a 1-1 mapping between the columns in the grid and the underlying datatable. I'm using infragistics v9.2
This is simply demonstrated by the following code, just drop it into a forms constructor. It creates a grid with a bound source column, a bound formula column and one unbound formula column. The calculated value depends on the first cell. It also adds a button that toggles the value of the first cell which should change the formula. Commenting out the line that assigns the formula to bound column 1 shows the unbound cell changing correctly.
Thanks, Martin
UltraGrid grid = new UltraGrid { Name = "grid", Dock = DockStyle.Fill }; grid.CalcManager = new UltraCalcManager(); Controls.Add(grid); DataTable dt = new DataTable(); dt.Columns.Add("col1", typeof(object)); dt.Columns.Add("col2", typeof(object)); dt.Rows.Add(new object[] { DBNull.Value, "" }); grid.DataSource = dt; grid.Rows.Band.Columns.Add("unbound"); grid.Rows.Band.Columns[1].Formula = "IF([col1] = \"\", \"Blank\", \"Value\")"; grid.Rows.Band.Columns[2].Formula = "IF([col1] = \"\", \"Blank\", \"Value\")"; UltraButton btn = new UltraButton() { Dock = DockStyle.Top, Text = "Toggle" }; Controls.Add(btn); btn.Click += (s, e) => dt.Rows[0][0] = dt.Rows[0][0] == DBNull.Value ? (object)1.0 : DBNull.Value;
Sorry we still have crossed wires, I'll try to make myself clearer!
I am _not_ changing the cell value of the formula column, I am changing the source cell to which the formula refers, and the problem I am reporting is that the dependent formula cell doesn't update if it is a bound column. Instead it causes a display issue where the source cell doesn't display the new value until the mouse passes over the cell and the formula cell doesn't recalculate. I've tried forcing the calc manager to update and that also has no effect.
The behaviour you describe is exactly what I want to happen, but it does not work on bound columns.
- I don't ever want to change the formula cell manually.
- I want it to write the calculated value to the underlying data source, as is described in the help
- I want the calc manager to recalculate it immediately when the source values change.
If this is a bug in 9.2 that is fixed in 10.x then maybe this is a reason for me to upgrade, but I need confirmation of this first...
Thanks,
Martin
Hi Martin,
marjones said:The column is only editable because that is the default on the grid in the small sample I put together. In my real use case I do indeed want the column to be read only.
Okay, that makes sense.
marjones said:In my post when I mentioned editing the cell manually I was referring to amending the source column that the formula depends on, not the formula column itself. If I do make the column read only I still get the same problem...
If you have a column in the grid that has a formula, then any changes you make in the grid or any other controls upon which that formula relies will cause the formula to be recalculated. This will, of course, blow away any value you assigned to the data source for that field.
There's no way for the grid to know that you don't want it to recalculate or update that field in the data source because you wrote to that field behind the grid's back, so to speak.
You could set the UltraCalcManager's CalcFrequency to Manual and that would give you the ability to choose when the calculations are performed. So maybe you just want to calculate the column once initially and then never recalculate it again after that and that would be a way to do it.
But by default, the calculations are performed continuously, updating the results any time something changes.
Hi Mike.
The column is only editable because that is the default on the grid in the small sample I put together. In my real use case I do indeed want the column to be read only.
In my post when I mentioned editing the cell manually I was referring to amending the source column that the formula depends on, not the formula column itself. If I do make the column read only I still get the same problem...
Thanks
Hi,
If you assign a Formula to any column, then the Formula calculation will overwrite any other value in the cell. There's no way to have a column with a Formula and also set the Value of the cell in the column to anything other than the formula result.
Generally speaking, you should always make a formula column readonly.