How to set value to a FormBuildIntControl on a Form?

Hi,

I have created a group (‘TotalsGrop’) under the design in a Form and have added FormBuildIntControl textboxes dynamically to the group. As I add the controls to the group I added the same controls to a List to access them later to set some integer values based on some calculation.

Here is the a portion of the code I have to add the control to the form

//adding text box controls
totalIntControl = _frmGrpControl.addControl(FormControlType::Integer, _oprId);
//totalIntControl.value(20); // here I have access to the value property to set a value
totalIntControl.width(30);
totalIntControl.label(_oprId + ’ Total:’);
summaryControlsList.addEnd(totalIntControl);

Here is the code where I am trying to retreive the FormBuildIntControl from the list (summaryControlsList) and trying to use the .value() property but I can’t see the value() property to set an int value.

public void displayTotals()
{

FormBuildIntControl     formBuildIntControl;
ListEnumerator          le = summaryControlsList.getEnumerator();
RouteOprId              routeOprId;
//int test;
while(le.moveNext())
{
    formBuildIntControl = le.current();
    routeOprId = formBuildIntControl.name();
    select OperationsSum, OprId from masMaxOprIdOprNumTmp
    where masMaxOprIdOprNumTmp.oprId == routeOprId;
    //formBuildIntControl.value(real2int(masMaxOprIdOprNumTmp.OperationsSum)); //I have access to the value() here but it doesn't display in the text box
    //formRun.design().controlName('TotalsGroup')... // can't get find the value() method
    
    
}

Is there a way to set values to the dynamically generated FormBuildIntControls on a Form?

Thanks,

Dave

In your situation, you should be using FormIntControl instead of FormBuildIntControl.

Then you can simply use the value() method:

totalIntControl.value(42);

If you want to find the control by name, the right code is this:

FormIntControl ctrl = element.design().controlName('MyControlName');
ctrl.value(42);

Thanks, Martin.

While building the control in the group I had to use the FormBuildIntControl and the addControl() of the group to be able to add control. Because addControl() method return type is FormBuildContorl so I can only assign it to the FormBuildControl.But while retrieving it from the list, in which the control has already been built and added to the Form design then I used FormIntControl to find on the formRun.design().control(formIntControl.id()); and then set the value using the value() method. Then it works.

You can simplify the whole by thing by doing it when controls have been built, when addControl() on group form control will return directly the FormControl, as demonstrated in my code above.

You called addControl() on a different object than I did, that’s why you got a different result. Unfortunately you didn’t show the context where you’re calling your code, and why you do it there. I choose a simpler design.