Search code examples
.netc#-4.0esriarcmaparcobjects

GeodatabaseUI.ICalculatorUI2 no longer works in ArcMap 10.1 (Why no Views?)


I have an addin that has been ported from ArcMap 9.3 to 10.1 and this code worked perfectly in 9.3 but for some reason won't work at all in 10.1:

ICalculatorUI calc = new CalculatorUI();
calc.Table = MyTable;
calc.Field = "MyField";
calc.DoModal(ArcMap.Application.hWnd);

The actual code is a little more complicated than that, but I've tried it with this simplified version and it still doesn't work.

What happens is the calculator dialog pops up just fine and I can enter a value to set the field to, but when I hit the OK button, the dialog closes without error, but nothing has been updated.

I've opened the table that I'm editing using ArcMap's regular ui and launched the Field Calculator on the same field and can confirm that it looks exactly like what I see when I use this bit of code on my own form. There are only three differences:

  • Prior to the dialog displaying, there's a warning dialog that pops up telling me that I'm not in an editing session and the changes can't be undone.
  • After the OK button is pressed, a progress dialog shows briefly while the rows are being updated.
  • The rows are actually updated.

So everything that is displayed on the dialog itself is identical, including the name of the field and the list of other fields in the table.

In ArcMap 9.3, the ICalculatorUI would take over everything as soon as DoModal was called. It annoyingly didn't even provide feedback programmatically to signify if the user canceled the dialog or [if/how many] rows were updated. Very black box and it sucked, but at least it worked!

I've not been able to find any help on this anywhere, especially not on ESRI's pathetic documentation, which appears to be copied and pasted from their 9.x documentation.

EDIT: Why no views? It's been several days and it's showing that the question has only been viewed twice, both of which were me (this edit makes 3). The other question I asked a year ago got the tumbleweed badge and the only activity was me making a comment - no answers and still only 40 views total (most of them mine, I'm sure). So what's up? Is SO putting my questions in a back closet somewhere?? I really do need some help with this...


Solution

  • I haven't tried to use ICalculatorUI prior to 10.1 but I would assume you need to use the ICalculator interface to do the actual calculations like so (assuming the calc variable as defined above in your question)

    ICalculator calculator = new Calculator();
    calculator.Expression = calc.Expression;
    calculator.PreExpression = calc.PreExpression;
    calculator.Field = "MyField";
    calculator.Cursor = table.Search(null, false);
    calculator.Calculate();