Question

In Dynamics AX 2012, is there a way to change the background color of multiple cells to different colors?

Order Status     Ship Status     Order ID
[green]          [red]           SO-1234
[green]          [green]         SO-1235
[red]            [red]           SO-1236

I've written a displayOption override that can change the color of one cell, but it seems to apply all the changes at the end, so whatever the last color you specify is the one that gets applied to all cells.

_options.backColor(46080); //green
_options.affectedElementsByControl(OrderStatus.id());

//is there anyway to apply the first change, so I can make a second one?

_options.backColor(255); //red
_options.affectedElementsByControl(ShipStatus.id());

In the code listed above, both cell background colors would be red.

Any suggestions?

Thanks

Was it helpful?

Solution

I had a similar task to accomplish, and I did not find a way to do it in Ax (well, techinically you could try Table control, but I strongly encourage you NOT to do so - you will end up swearing out aloud).

What I did is implemented a WPF user control and used this post as a template. This is a small tutorial (found in Answer #7) which shows how to implement a cell background converter in built-in WPF data grid control, to accomplish the task.

After you have it implemented you can populate your datagrid by using LINQ (if using AX 2012 R2), web services, or passing a temporary table - there are many ways to access AX data.

It may not be the ultimate solution, but it works.

OTHER TIPS

I did it using a table control ( although Maciej advised you not to do ). It works without problems.

You need to add a table control which gets your data and set the property ColorScheme to RGB

Then, override the FormControl editControl(int column, int row) You can access each value by value = data.cell(column, row).data(); whereby data is the name of the table control. Beware, that you have to add a control with the correct datatype to the table control and give it a name. Also set the ColorScheme property to RGB.

If you got RGB values for your desired background color, setting this color can be done by

RealEdit.backgroundColor(WinAPI::RGB2int(real2int(R),real2int(G),real2int(B)));

RealEdit is the name of the added control.

I've done this to display a matrix filled with values between 0 and 1 and to display a color gradient overlay with a range from green to red. See this link, if you like more information about the color conversion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top