In this article we are going to explain how to change the color of a row, column or a specific cell in a grid.

  1. Identify the data source of your grid
  2. Locate the data source under the data sources node of your form.
  3. Override the method “displayOption”
  4. Create a color and set the color as needed.

Change the color of a row

To change the color of a row, we decelerate a buffer of the data source type and copy the values of the record received as parameter to the buffer, then we check a specific value and set the color to the object of the type FormRowDisplayOptionusing using its method “backColor”.

 

public void displayOption(Common _record, FormRowDisplayOption _options)

{

int                myColor = WinApi::RGB2int(50,255,50);

TestGridColorTable testGridColorTable_Color;

;

testGridColorTable_Color.data(_record.data());

if(testGridColorTable_Color.Class == “A”)

{

_options.backColor(myColor);

}

super(_record, _options);

}

1

 

Change the color of a column

To change the color of a column we need to locate within the grid the control that corresponds to the field and change its AutoDeclaration property value to Yes.

 

We set the color as we did to change the row color but after that we use the method affectedElementsByControl to specify which control will be affected, for this we enter the name of the control and get the id using its method “id”.

 

public void displayOption(Common _record, FormRowDisplayOption _options)

{

int                myColor = WinApi::RGB2int(50,255,50);

;

_options.backColor(myColor);

_options.affectedElementsByControl(TestGridColorTable_Id.id());

super(_record, _options);

}

2

Change the color of a column

To change the color of a specific cell we can follow the same approach we used to change the column color but we will need to specify conditions to identify what row and column to modify.

public void displayOption(Common _record, FormRowDisplayOption _options)

{

int                myColor = WinApi::RGB2int(50,255,50);

TestGridColorTable testGridColorTable_Color;

;

testGridColorTable_Color.data(_record.data());

if(testGridColorTable_Color.Class == “A” &&

testGridColorTable_Color.Value > 50)

{

_options.backColor(myColor);

_options.affectedElementsByControl(TestGridColorTable_Value.id());

}

super(_record, _options);

}

 

3