Change the background color of a column in a grid

我只是一个虾纸丫 提交于 2019-12-22 08:46:08

问题


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

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.


回答1:


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();


来源:https://stackoverflow.com/questions/12621719/change-the-background-color-of-a-column-in-a-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!