Thursday, May 16, 2013

How to change the color of a single colum in Ax forms

We can override the displayOption() method of the form's datasource
to change appearance of any column in the grid.

For highlighting one or more cells, override the displayOption()  use

_options.affectedElementsByControl() method.

 //if it is condition based
public void displayOption(Common _record, FormRowDisplayOption _options)
{
   Test            _test;
    noyes          value;
    ;
    _test = _record;
    if(_test.SO > _test.PO)
        value = NoYes::Yes;
    else
        value = NoYes::No;
    switch(value)
    {
        case NoYes::Yes :
         _options.backColor(WinAPI::RGB2int(255,0,0));
        _options.affectedElementsByControl(Test_PO.id());
        break;
        case NoYes::No :
        _options.backColor(WinAPI::RGB2int(255,255,255));
       _options.affectedElementsByControl(Test_PO.id());
    }
}

//if no condition
public void displayOption(Common _record, FormRowDisplayOption _options)
{
  _options.backColor(WinApi::RGB2int(0,255,0));
  _options.affectedElementsByControl(Control1.id());
  _options.affectedElementsByControl(Control2.id());

}

No comments: