Olaru Mircea
Olaru Mircea

Reputation: 2620

Change width of a lookup column

I've created a lookup with two columns, first one containing and integer which works just fine but the second one has a long name and this is where the problem arises. Users should horizontally scroll in order to check the entire string and even in that case, the column's width is not big enough to display the whole data.

I've found this :

Adjusting column width on form control lookup

But i don't understand exactly where and what to add.

I am not sure but maybe I have to add the fact that this lookup is used on a menu item which points to an SSRS report, in the parameters section.

Update 1:

I got it working with a lookup form called like this :

Args args;
FormRun formRun;
;

args = new Args();

args.name(formstr(LookupOMOperatingUnit));
args.caller(_control);
formRun = classfactory.formRunClass(args);
formRun.init();
_control.performFormLookup(formRun);

and in the init method of this form i added:

public void init()
{
    super();
    element.selectMode(OMOperatingUnit_OMOperatingUnitNumber);
}

meaning the field i really need.

enter image description here

I am not sure i understand the mechanism completely but it seems it knows how to return this exact field to the DialogField from where it really started.

In order to make it look like a lookup, i have kept the style of the Design as Auto but changed the WindowType to Popup, HideToolBar to Yes and Frame to Border.

Upvotes: 2

Views: 4465

Answers (2)

li li
li li

Reputation: 1

you can extends the sysTableLookup class and override the buildFromGridDesign method to set the grid control width.

protected void buildFormGridDesign(FormBuildGridControl _formBuildGridControl)
{
    if (gridWidth > 0)
    {
        _formBuildGridControl.allowEdit(true);
        _formBuildGridControl.showRowLabels(false);
        _formBuildGridControl.widthMode(2);
        _formBuildGridControl.width(gridWidth);
    }
    else
    {
        super(_formBuildGridControl);
    }

}

Upvotes: 0

Jan B. Kjeldsen
Jan B. Kjeldsen

Reputation: 18051

Probably the best route is do a custom lookup and change the extended data type of the key field to reflect that. In this way the change is reflected in all places. See form FiscalCalendarYearLookup and EDT FiscalYearName as an example of that.

If you only need to change a single place, the easy option is to override performFormLookup on the calling form. You should also override the DisplayLength property of the extended data type of the long field.

public void performFormLookup(FormRun _form, FormStringControl _formControl)
{
    FormGridControl grid = _form.control(_form.controlId('grid'));
    grid.autoSizeColumns(false);
    super(_form,_formControl);
}

This will not help you unless you have a form, which may not be the case in this report scenario.

Starting in AX 2009 the kernel by default auto-updates the control sizes based on actual record content. This was a cause of much frustration as the sizes was small when there was no records and these sizes were saved! Also the performance of the auto-update was initially bad in some situations. As an afterthought the grid control autoSizeColumns method was provided but it was unfortunately never exposed as a property.

Upvotes: 4

Related Questions