private void ShowFormulaDialog() { UltraGridColumn column = this.FirstGridBand.Columns["UsageFormula"]; if (column == null) { return; } this.ShowFormulaBuilderDialog(column as IFormulaProvider); } private void ShowFormulaBuilderDialog(IFormulaProvider formulaProvider) { // Declare a new FormulaBuilderDialog FormulaBuilderDialog formulaBuilderDialog = null; try { formulaBuilderDialog = new FormulaBuilderDialog(formulaProvider); formulaBuilderDialog.OperandInitializing += new OperandInitializingEventHandler(this.formulaBuilder_OperandInitializing); formulaBuilderDialog.FunctionInitializing += new FunctionInitializingEventHandler(this.formulaBuilder_FunctionInitializing); // Show the dialog DialogResult dResult = formulaBuilderDialog.ShowDialog(this); // If the user cancelled, do nothing if (dResult == DialogResult.Cancel) return; // Apply the formula formulaProvider.Formula = formulaBuilderDialog.Formula; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (formulaBuilderDialog != null) { // Whatever happens, make sure we disconnect from // the events formulaBuilderDialog.OperandInitializing -= new OperandInitializingEventHandler(this.formulaBuilder_OperandInitializing); formulaBuilderDialog.FunctionInitializing -= new FunctionInitializingEventHandler(this.formulaBuilder_FunctionInitializing); formulaBuilderDialog.Dispose(); formulaBuilderDialog = null; } } }