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());

}

How change the color of entire row

We can override the displayOption() method of the form's datasource 
to change appearance of any row in the grid. U can set either the 
foreground or the background color of the row.
public void displayOption(Common _record, FormRowDisplayOption _options)
{
    Test  _test;//Table Name
    noyes       value;
    ;
   _test = _record;
    if(_test.SOqty > _test.POqty)        value = NoYes::Yes;     else         value = NoYes::No;
    switch(value)
    {
        case NoYes::Yes :
         _options.backColor(WinAPI::RGB2int(255,0,0));
        break;
        case NoYes::No :
        _options.backColor(WinAPI::RGB2int(255,255,255));
    }
    //super(_record, _options);
} 
in this case where ever saleQty is greater than PurchQty then that entire row will change to red color.maximun this color display option will help for retails forms.