Splitter Control

From Axaptapedia

Jump to: navigation, search

Surprise, Surprise! Axapta 3.0 has no splitter control. Still in very few forms (sales order entry for example) and in the tutorial you will find examples, how to emulate a splitter behaviour in Axapta.


Here is a summary how this trick is achieved:

Lets assume you have a design with two group controls, LeftGroup and RightGroup. To have these two groups next to each other you set the property columns=2 in the design. Now you would like to have a splitter between these two group controls, so that you can resize/shift the controls horizontally. To achieve this do the following:

1. Create a new group control, called SplitterGroup and position it in the design tree between the existing two group controls. This group control will be used to emulate a real splitter control.

2. In this new SplitterGroup control set the following parameters:

    AlignChild       = No
    AlignControl     = Yes
    AutoDeclaration  = Yes
    FrameType        = Raised3D
    Height           = ColumnHeight
    HideIfEmpty      = No
    Width            = 4

3. In the LeftGroup control set the initial width, for example 250 pix:

    Width            = 250
    Height           = ColumnHeight
    AutoDeclaration  = Yes

4. In the Rightgroup control set:

    Height           = ColumnHeight
    Width            = ColumnWidth

5. We have now 3 columns, so in the containing design set:

    Columns         = 3

6. As I said the splitter is just emulated by our SplitterGroup control, therefore we have to add some magic. The majority of this is implemented by Axapta in the class SysFormSplitter_X or SysFormSplitter_Y. In our case, we use the SysFormSplitter_X and declare it in the class declaration of our form:

public class FormRun extends ObjectRun
{
    SysFormSplitter_X  sysFormSplitter_
}

7. We initialize the Axapta class in the init method of our form. The StartupHeight parameter is often omitted since it is optional. However, failing to provide a default will result in your splitter not working correctly when the user opens it for the first time. The user will have to exit the form and open it again. Providing a default (does not matter how much) will make sure the splitter always works:

public void init()
{
    super();
 
    sysFormSplitter_X = new SysFormSplitter_X(SplitterGroup,LeftGroup,element,100);
}

8. And we use it in several mouse events of our SplitterGroup control:

int mouseDown(int x, int y, int button, Boolean Ctrl, Boolean Shift)
{
    int ret = super(x,y,button,ctrl,shift);
    ;
    
    sysFormSplitter_X.mouseDown(x,y,button,ctrl,shift);
    return ret;
}

int mouseMove(int x, int y, int button, Boolean Ctrl, Boolean Shift)
{
    ;
 
    super(x,y,button,ctrl,shift);
 
    return sysFormSplitter_X.mouseMove(x,y,button,ctrl,shift);
}

int mouseUp(int x, int y, int button, Boolean Ctrl, Boolean Shift)
{
    int ret =  super(x,y,button,ctrl,shift);
    ;
 
    sysFormSplitter_X.mouseUp(x,y,button,ctrl,shift);
    return ret;
}

That's it! We now have a working X-Splitter. It took some manual tweaking, but behaves as expected.

[edit] Y-splitter

An identical method can be followed to produce a form with a Y-splitter (for example, the SalesTable form in standard Dynamics Ax). In this case the Left Group mentioned above will be the top group, and the right group becomes the bottom group.

You should swap the Width and Height properties which are set in the instructions (for example in the LeftGroup)

In addition you should ensure that the Columns setting on the Design node is changed to 1 (one) from the default of 2 (two). Otherwise the form will not display correctly.

Enjoy,

--Markus Schmitz 05:01, 16 Jun 2005 (EDT)

[edit] Fix for SysFormSplitter_X class

When form with vertical splitter is used first time, in Ax30 user is not able to use it (dragging of a splitter has no effect). To fix this behavoiur change the new constructor of the SysFormSplitter_X class as following:

...
if (_startUpWidth)
    curWidth = _startUpWidth;
 
// add these lines:
else if (_sizeControl)
    curWidth = _sizeControl.widthValue();
 
if (!curWidth)
    curWidth = 150;
...

(fix by Maxim Gorbunov from AxForum )

Personal tools