Как раскрасить строку tDB*Grid в зависимости от поля?

Вопросы программирования и использования MSEide + MSEgui.

Модератор: Модераторы

Как раскрасить строку tDB*Grid в зависимости от поля?

Сообщение t-ea » 19.12.2013 14:57:58

Есть таблица с данными, например:
Код: Выделить всё
Наименование Начало       Конец        Сделано
----------------------------------------------
Заседание    01.01.2013   02.02.2013   Да
Собрание     07.01.2013   07.01.2013   Нет
Праздник     01.02.2013   31.12.2013


В tDBStringGrid из этих колонок выводится только поле 'Наименование'.
Как сделать, чтобы строка, с «Заседание», была перечёркнута, а фон «Собрание», например, был бы красный?

Я так подозреваю, что надо что-то делать с CellInfo.DataPo^. в OnBeforeDrawCell, но вот как?
t-ea
новенький
 
Сообщения: 98
Зарегистрирован: 22.09.2006 00:22:34

Re: Как раскрасить строку tDB*Grid в зависимости от поля?

Сообщение hovadur » 19.12.2013 16:17:21

t-ea писал(а):Я так подозреваю, что надо что-то делать с CellInfo.DataPo^. в OnBeforeDrawCell, но вот как?

Не в OnBeforeDrawCell как в delphi, а OnPrepareCanvas, как написано здесь http://wiki.lazarus.freepascal.org/Grid ... ng_process
Пример кода:
Код: Выделить всё
procedure TfrmMus.DBGridPrepareCanvas(sender: TObject; DataCol: Integer;
  Column: TColumn; AState: TGridDrawState);
var
  Grid: TCustomDBGrid;
  D: TDataSet;
begin
  Grid := TCustomDBGrid(Sender);
  if (Column.FieldName = 'INUSL') then begin
    D := Column.Field.DataSet;
    if D.FieldByName('mex').AsInteger <> 1 then begin
      Grid.Canvas.Brush.Color := clRed;;
      Grid.Canvas.Font.Color := clMenuText;
    end;
  end;
end;
hovadur
постоялец
 
Сообщения: 116
Зарегистрирован: 31.01.2013 15:50:41

Re: Как раскрасить строку tDB*Grid в зависимости от поля?

Сообщение mse » 19.12.2013 17:24:01

In order to set the row background color by a DB field:
- define the colors in t*grid.rowcolors.
- create an integer field which holds the color index, possibly it is a fkCalculated or fkInternalCalc field.
- select the color field in tdb*grid.datalink.fieldname_color.
- disable options1 co1_rowcolor in columns which should not change the background color.
An example is in mseuniverse/samples/db/gridcolorlines.
https://gitorious.org/mseuniverse/mseuniverse
It is also possible to select the font and merged, readonly and selected state of rows by a data field.

If you want to use onbeforedrawcell set cellinfo.color depending on the field value. Working with datapo is maybe a little bit dangerous, possibly the dataset cursor should be placed to the current row in the drawing events, I'll have a look.
The grid data can be accessed in tdbwidgetgrid by <editwidget>[cellinfo.cell.row], in tdbstringgrid by <column>[cellinfo.cell.row].

Posted after 1 hour 10 minutes 32 seconds:
mse писал(а):possibly the dataset cursor should be placed to the current row in the drawing events, I'll have a look.

Done, git master f7b4a55483e56e0f25cfc02864e6d0a3ca9650b0.
Вложения
rowcolor.png
rowcolor.png (10.64 КБ) Просмотров: 7120
mse
новенький
 
Сообщения: 68
Зарегистрирован: 08.08.2013 15:40:31


Вернуться в MSEide + MSEgui

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 3

Рейтинг@Mail.ru