Wednesday, 1 October 2014

Go To Line number feature in AX 2012

Here is the code snippet, which would help in locating the line number in a string control which has got multiple lines.

static void gotoLineNum(FormStringControl   _control,   int _gotoLine)
{
    int lineCount;

    int i;
    int gotoLineNum;
    int lengthTotal;
    int selectToPos;
    str lineText;

    #define.SPACE(' ')

    lineCount = _control.getLineCount();
    gotoLineNum = _gotoLine;

    for (i = 0; i<= lineCount-1; i++)
    {
        if (i == gotoLineNum-1)
        {
            break;
        }
        if (i == 0)
        {
            lineText = #SPACE + _control.getLine(i);
        }
        else
        {
            lineText = strRep(#SPACE, 2) + _control.getLine(i) ;
        }

        lengthTotal += strLen(lineText);
    }

    lineText =  #SPACE + _control.getLine(i);
    selectToPos = lengthTotal + strLen(lineText);

    lengthTotal = (i==0) ? 0 : lengthTotal+1;

    _control.setSelection(lengthTotal, selectToPos);

    _control.setFocus();
}

No comments:

Post a Comment