Interview Questions

Monday, April 28, 2014

Coloring Grids in DAX

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 rowsCode :
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 formtutorial_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. :)

No comments:

Post a Comment