4

I have following form and I want to change the background color of a column, based on the values of other columns; enter image description here

In the orange columns, instead of displaying orange background, I want the cell color to be the RGB combo of Red, Green & Blue fields under COLOR ATTRIBUTES section.

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
Bilal Saeed
  • 603
  • 2
  • 10
  • 24

2 Answers2

6

Let's say that the control the background of which you need to change is named FirstFieldControl. Set its AutoDeclaration property to Yes and BackgroundColor to Window background.

Now you need to override the displayOption method on your datasource, e.g.:

public void displayOption(Common _record, FormRowDisplayOption _options)
{
    YourTable   yourTable   = _record;
    int         color;
    ;

    switch (yourTable.Name)
    {
         case 'Red' :
                 color = WINAPI::rgbCon2int([255, 0, 0]);
                 break;
         case 'Green' :
                 color = WINAPI::rgbCon2int([0, 255, 0]);
                 break;
         case 'Blue' :
                 color = WINAPI::rgbCon2int([0, 0, 255]);
                 break;
    }

    if (color)
    {
        _options.backColor(color);
        _options.affectedElementsByControl(FirstFieldControl.id());
    }
    else
    {
        super(_record, _options);
    }
}

This is just an example to give you an idea - don't copy-paste :)

It's easier to store the color value in the table, then the code will be much nicer.

P.S. If you're changing the colors run-time you might need to use the following piece of code to refresh the record:

yourTable_ds.clearDisplayOption(yourTable);
yourTable_ds.refresh();
10p
  • 5,488
  • 22
  • 30
  • This is the right answer. Just to add some extra information, overriding this method has a very bad impact on performance of forms with lots of rows, so do it if you really need it, but it's not recommended only for esthetical purposes. – j.a.estevan Sep 28 '12 at 09:46
  • To speed things up precompute the color values in the `init` method. – Jan B. Kjeldsen Oct 10 '12 at 11:40
0

I want to show variable color according to warehouse in on-hand form. If I override displayOption on inventdim datasource, it does get called. It does get called if I override InventSum datasource. But I cannot get the actual inventdim record. In this form, InventSum is master table, and InventDim is the joined child table.

Duan Xin
  • 11
  • 2