WINDOWS Live Search

To contact me for any clarifications regarding any posts / information, please mail me at arijit [dot] basu [at] gmail [dot] com


Sunday, April 8, 2007

Coloring Grids in DAX

tutHeres some tips on how to color Grid Cells / rows in DAX. Ive used the prodTable form as an example.The code must be placed in the displayOption() method of the datasource.
Case 1:
Color specific rows
Code :
public void displayOption(Common _record, FormRowDisplayOption _options)
{

prodtable prodtablelocal;

prodtablelocal = _record;

Switch(prodtablelocal.ProdStatus)

{

Case ProdStatus::Created:

_options.backColor(6029311); //Light Yellow

_options.textColor(12582912); //Blue

Break;

Case ProdStatus::Completed:
_options.backColor(16761281); //Light Blue
_options.textColor(12582912); //Blue
Break;
}
}

Display:




Case 2:
Color specific cells
Code :

public void displayOption(Common _record, FormRowDisplayOption _options)

{

prodtable prodtablelocal;

prodtablelocal = _record;

Switch(prodtablelocal.ProdStatus)
{
Case ProdStatus::Created:

_options.backColor(65535); //Light Yellow

_options.affectedElementsByControl(ProdTable_ProdId.id());
Break;

Case ProdStatus::Released:

_options.backColor(8421631); //Light Red

_options.affectedElementsByControl(ProdTable_ProdId.id());

Break;
Case ProdStatus::Completed:
_options.backColor(65408); //Light Green
_options.affectedElementsByControl(ProdTable_ProdId.id());
Break;

}

}

Display:


Now to get the color codes u want , look at the form tutorial_Form_DisplayOptions.

Tweak it a bit by adding this line in
\Forms\tutorial_Form_DisplayOptions\Designs\Design\[ButtonGroup:ButtonGroup]\Button:SetColor\Methods\clicked()

if (conlen(c))
{ backColor = WinAPI::RGB2int( conpeek(c,1), conpeek(c,2), conpeek(c,3) );
Info(Strfmt("%1",backColor)); // Add this line
// Clear the display options for the once which allready has been set.
for (common = custTable_ds.getFirst(); common; common = custTable_ds.getNext())
{
........
When u run the form & select the color u want, the int value will be there in the infolog :)
If you want to turn off active highlighting then select the Grid, Click on Properties & Set the property ' HighlightActive' to No. :)


Happy DAX-ing :)



9 comments:

Zubair Ahmed said...

Thanx Arijit,

that was helpful.

Anonymous said...

nice one. i thought coloring could be done only through winAPI. this is good.

Anonymous said...

Thanks, helped a lot. Now how do you get the grid to change color if you change order status without having to leave the form and come back in?

Jack Koh said...

Hi Arijit,

May i know how you get the color integer?

Thank you

Jack Koh said...

Hi Arijit,

May i know how you get the color integer?

Thank you

Anonymous said...

when you select a line in the grid, the background color turns blue. Is there any way to keep the same backgroundcolor ?

juajuajua said...

Hi. Thank you for this tip. we were trying to work with the FORMTABLEControl in order to color an specific cell, but it was kind of hard that way.
Best Regards. Camilo Virguez.

Anonymous said...

i need diffrent color in one row....????

Ivan (Vanya) Kashperuk said...

Just as an information to people who read this, you don't actually have to know the integer combinations for all the color codes. Just use a method like WinAPI::RGB2Int() in order to get the int value for an RGB color.
For example, WinAPI::RGB2Int(255, 255, 0) will give you the color yellow.