web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Multiselect lookup on a Grid Control

(0) ShareShare
ReportReport
Posted on by 190

Hello everyone, 

I have to create a multiselect lookup on a grid Control. I have tried the following:

In Class declaration:

SysLookupMultiSelectCtrl    msCtrl;

In form's init method:

msCtrl = SysLookupMultiSelectCtrl::construct(element, GridControl, queryStr(aotQueryName));

When the control isn't in grid, it works. But when i try the above code on my GridControl it blocks the system. 

Can anyone help please? 

Thanks in advance!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Did you place your code in init after the super call? It must be there, otherwise the controls simply do not exist yet which you could refer.

    Also you could try using SysLookupMultiSelectGrid instead.

  • Elda Mataj Profile Picture
    190 on at

    Thank-you for your reply. Actually, yes I had written it after super.

    Now, I am using SysLookupMultiSelectGrid . I have the following code:

    In class declaration:

    SysLookupMultiSelectGrid    msGrid;

    In form's init method(after super):

    msGrid = SysLookupMultiSelectGrid::construct(GridControl,GridControl);

    In GridControl lookup method:

    Query query = new Query(queryStr(aotQueryName));

       super();

       msGrid.parmQuery(query);

       msGrid.run();

    The problem is that when I choose one value(or multiple values) from one line, all other lines of grid are filled up automatically. I don't know why this happen

    .33080.Capture.JPG

    Can anyone help ?

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    It is because the value is not bound to the specific record lines' field, but to the form control, so the same value is rendered across the whole grid.

    If it does not write the values over actually in the backend for the other records, then you don't have to worry about it.

    You could try to move the control off from the Overview tab pages' grid to the General tab page in a regular field group, then it would behave as expected.

  • Elda Mataj Profile Picture
    190 on at

    I understand, Actually I need to write the values in the backend. I tried to make the control bound, but the multiselection doesn't work with bound control. So what i have done right now is that i have the control unbound and in the modified method of my control, i  have(after super):

    ttsBegin;

       MyTable.Myfield= GridControl.text();

       MyTable.update();

       ttsCommit;

    Is there any way that multiselection to function even in bound control. So to perform multiselection lookup on  GridControl and then to save the data on the MyTable.MyField(connected to the bound GridControl)

    Thanks.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Not too sure, I rarely work with multiselect lookups and mostly in parameter/reporting scenarios, it is not typical to use it in a grid. You could try to use cross-references on the class to see how it is implemented in Standard AX forms, maybe you'll have your answer there.

    If your original request that the lookup does not work and blocks the system is resolved, kindly mark helpful answers to resolve the thread.

  • Suggested answer
    diana.v Profile Picture
    20 on at

    Hello Eva,

    I have the same requirement and find next solution how to use multiSelectCtrl lookup inside Grid control and save data in table.

    Maybe it would be helpful for someone.

    1. Create your own class or modify standard like in the next example - http://dynamicaxassist.blogspot.com/2016/01/using-multi-select-lookup-on-string.html

    I have created my own class copy of SysLookupMultiSelectCtrl with the next changes:

    • new method isOnGrid()
    public boolean isOnGrid(FormStringControl _ctrl)
    {
        FormControl     parentControl;
        FormControl     currentControl;
        boolean         retValue;
    
        currentControl  = _ctrl;
        retValue        = false;
    
        while(currentControl.parentControl() && !retValue)
        {
            parentControl = currentControl.parentControl();
    
            if(parentControl is FormGridControl)
            {
                retValue = true;
            }
            else
            {
                currentControl = currentControl.parentControl();
            }
        }
        return retValue;
    }
    • add following code in init()
    public void init()
    {
        frmRun.lock();
    
        fsCtrlIds = frmRun.design().addControl(FormControlType::String, fsCtrlNames.name() + '_Ids');
        fsCtrlIds.extendedDataType(fsCtrlNames.extendedDataType());
        fsCtrlNamesTmp = frmRun.design().addControl(FormControlType::String, fsCtrlNames.name() + '_Tmp');
        fsCtrlNamesTmp.extendedDataType(fsCtrlNames.extendedDataType());
    
        // set the value in ctrlNames to the same as the one in the original ctrl. Required if data is loaded from SysLastValue.
        fsCtrlNamesTmp.text(fsCtrlNames.valueStr());
    
        if(this.isOnGrid(fsCtrlNames))
        {
            fsCtrlNames.registerOverrideMethod('modified', 'ctrlNames_textChange', this);
        }
        else
        {
            fsCtrlNames.registerOverrideMethod('textChange', 'ctrlNames_textChange', this);
        }
    
        fsCtrlNames.registerOverrideMethod('lookup', 'ctrlNames_lookup', this);
    
        fsCtrlIds.visible(false);
        fsCtrlNamesTmp.visible(false);
        fsCtrlIds.enabled(false);
        fsCtrlNamesTmp.enabled(false);
    
        fsCtrlNames.mandatory(isMandatory);
        fsCtrlNames.lookupButton(FormLookupButton::Always);
    
        frmRun.resetSize();
    
        frmRun.unLock();
    }
    • add following code in the ctrlNames_textChange()
    public void ctrlNames_textChange(FormStringControl _fsCtrlNames)
    {
        FormDataSource      fds;
        Common              anyBuffer;
    
        _fsCtrlNames.text(fsCtrlNamesTmp.text());
        fds = _fsCtrlNames.dataSourceObject();
    
        if(fds)
        {
            anyBuffer = fds.cursor();
            anyBuffer.(_fsCtrlNames.dataField()) = fsCtrlNamesTmp.text();
            fds.refresh();
        }
    
        fsCtrlNames.modified();
    }

    2. Then declare in class declaration of your form your multiselect control(use your newly created class):

    SysLookupMultiSelectCtrl msCtrl;

    Set auto declaration property of the MsStringControl to Yes. Bound control to the datasource field.

    In init method of your form write the following code after super():

    msCtrl = SysLookupMultiSelectCtrl::construct(element, MsStringControl, querystr(AOTQuery));

    Create following method in the form:

    public void setCtrlLookupValues()
    {
        container ids;
        container recIds;
        int i;
    
        for (i = 1; i <= conLen(str2con(YourTable.FieldLinkedToMsCtrl, ";")); i++)
        {
            recIds += LookupTable::find(conPeek(str2con(YourTable.FieldLinkedToMsCtrl, ";"), i)).RecId;
            ids += conPeek(str2con(YourTable.FieldLinkedToMsCtrl, ";"), i);
        }
    
        msCtrl.set([recIds,ids]);
    
        ids = conNull();
        recIds = conNull();
    }

    This method is used to fetch the values from table to your multiselect control.


    Call the method setCtrlLookupValues() in active method of your datasource:

    public int active()
    {
        int ret;
    
        ret = super();
    
        element.setCtrlLookupValues();
    
        return ret;
    }

    Override modified method of your string field namely MsStringControl  add following code:

    public boolean modified()
    {
        boolean ret;
    
        ret = super();
    
        YourTable.FieldLinkedToMsCtrl = this.text();
        YourTable.write();
    YourTable_ds.reread();
    YourTable_ds.refresh(); return ret; }


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans