Search code examples
axaptadynamics-ax-2012x++

How to set the values of a Combobox which programmatically added in a grid


I have a grid which for some reasons I added dynamically a combobox. I have done it and working like charm.

The next thing which I am stack is how to set the selection for each row per code.

for example in first row of the gird the combobox I want to has the value X and in the second row I would like to has the value Y.

    FormGridControl grid = sender.formRun().design(0).controlName('FormGridControl1');
    ColumnTable columnTable;
    ValueTable valueTable;

    while select * from columnTable
    {
        FormComboBoxControl combo1 = grid.addControl(FormControlType::ComboBox,columnTable.Name);
        combo1.label(columnTable.Name);
        combo1.enumType(enumNum(enumValue));;

        combo1.registerOverrideMethod(methodStr(FormComboBoxControl, SelectionChange),'DynamicComboControl_SelectionChanged',this);

        while select * from valueTable
           where valueTable.ColumnName ==  columnTable.Name
        {
           // at this place I have to set the values of the combo1 for each line of the grid separately.
           // and I have not any idea how I can do this.
        }



    }

Can someone help me please?


Solution

  • You never assigns values to grid fields using a loop.

    If the data in your field in the grid comes from a field of the datasource then use a bound field (maybe created dynamically by addDataField).

     fc = grid.addDataField(fbds.id(), fieldNum(MyTable,MyField));
    

    If your data field can be computed by some method add a display method.
    Added dynamically like this:

    name = tableMethodStr(MyTable,myMethod);
    fc = grid.addControl(FormControlType::ComboBox, ds.name()+'_'+name);
    fc.dataSource(grid.datasource());
    fc.dataMethod(name);
    

    If your data can be edited, then the method must be an edit method. Added dynamically the same way as a display method.