how do i color a column in grid based on a condition

Hi All,

how do i color a column in grid based on a condition?my requirement is like if the condition is not met,that particular column is highlighted red.

In AX 2012, XYZ/Project management and accounting/Common/Timesheets/All timesheets

While editing a timesheet ,we have no. of hours per day a worker has to work.If its less than min no. of hours,that particular column should get highlighted red.

I have tried display option method in form datasource “TSTimesheetlineweek”,but no success.

:slight_smile:

what code have you written to highlight the column ??

Can you share it ??

public void displayOption(Common _record, FormRowDisplayOption _options)

{

TSTimesheetLineWeek _TSTimesheetLineWeek = _record;

Real minhours = 8.00;

;

if (TSTimesheetLineWeek.Hours[1] < minhours )

{

_options.backColor(8421631);

_options.affectedElementsByControl(TSTimesheetLineWeek.Hours[1].id());

//(here i am getting an error,“Variable TSTimesheetLineWeek_Hours has not been declared.” Even after making AutoDeclaration “Yes”)//

}

super(_record, _options);

}

Same I tried in active method also,

public int active()

{

int ret;

real minhours = 8.00;

int i;

;

if (TSTimesheetLineWeek.Hours[1] < minhours )

{

TSTimesheetLineWeek_Hours[1].colorScheme(FormColorScheme::RGB);

TSTimesheetLineWeek_Hours[1].backgroundColor(Winapi::rgb2int(255,0,0));

}

else

{

TSTimesheetLineWeek_Hours[1].colorScheme(FormColorScheme::RGB);

TSTimesheetLineWeek_Hours[1].backgroundColor(Winapi::rgb2int(255,255,255));

}

ret = super();

return ret;

}

Again same error!! “Variable TSTimesheetLineWeek_Hours has not been declared.”

Hi Shyam,

http://chaituax.wordpress.com/2013/03/07/changing-color-of-records-based-on-flag-in-ax/

this might help you…

My problem is why the form design control name “TSTimesheetLineWeek_Hours[1]” is not getting declared,even after making Auto Declaration “Yes”.

Otherwise the code is correct in active method,its working fine for other form design control.

That’s a good question that I am interested in since I am recently also new to a grid UI control. The suggestions here are quite helpful, it could be better if I can see more codes demonstrating the method. Is there something like the grid color column? However, this thread already helped me a lot with much insights offered. Cheers.