Reply To: TRzDBGrid.QuickCompare

#2636
Peter Dzomlija
Participant

    Thanks Ray. You have been a great help.

    Since my last reply, I have learned that I can use

    TDBGrid(Sender).DataSource.DataSet.FieldValues[DataModule1._FXQueryBusy.FieldName];

    to determine the appropriate values of other fields.

    The following code is what I use for <u>OnDrawColumnCell</u>. Perhaps it will be off assistance to others who have a similar:

    procedure TFormMain.DBGridDataDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
          procedure DrawBooleanValue(AValue:Boolean; AImageIndex:Integer; AFieldName:string);
          begin
            if (CompareText(Column.Field.FieldName, AFieldName)=0) then
              if AValue then
                ImageListGrid.Draw(DBGridData.Canvas, Rect.Left+((Rect.Width - ImageListGrid.Width) div 2),
                                                      Rect.Top+((Rect.Height - ImageListGrid.Height) div 2), AImageIndex);
          end;
    begin
      with Sender as TDBGrid do
        if DataSource.DataSet.RecordCount > 0 then
          begin
            {Row Background}
            if (gdSelected in State) or (gdRowSelected in State) then
              Canvas.Brush.Color := clHighlight
            else
              if Odd(DataSource.DataSet.RecNo) then
                Canvas.Brush.Color := clWindow
              else
                Canvas.Brush.Color := $00FAFAFA;
    
            Canvas.FillRect(Rect);
    
            {Cell Values}
            if not Assigned(Column.Field) then
              DefaultDrawColumnCell(Rect, DataCol, Column, State)
            else
              {Boolean Fields must be drawn using a TImagelist glyph}
              if Column.Field.InheritsFrom(TBooleanField) then with TBooleanField(Column.Field) do
                begin
                  DrawBooleanValue(not Value, 1, DataModule1._FXIsValid.FieldName);
                  DrawBooleanValue(Value, 0, DataModule1._FXBusy.FieldName);
                end
              else
                {Change the font style/color}
                with DataModule1, Column.Field do
                  begin
                    if not DataSource.DataSet.FieldValues[DataModule1._FXIsValid.FieldName] then
                      begin
                        Canvas.Font.Style := [fsStrikeOut];
                        Canvas.Font.Color := IfThen(gdSelected in State, clHighLightText, clRed);
                      end
                    else
                      if DataSource.DataSet.FieldValues[DataModule1._FXBusy.FieldName] then
                        begin
                          Canvas.Font.Style := [fsItalic];
                          Canvas.Font.Color := IfThen(gdSelected in State, clHighLightText, clGreen);
                        end
                      else
                        begin
                          Canvas.Font.Style := [];
                          Canvas.Font.Color := IfThen(gdSelected in State, clHighLightText, clWindowText);
                        end;
    
                    {Continue Drawing}
                    DefaultDrawColumnCell(Rect, DataCol, Column, State);
                  end;
          end
        else
          DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
    

    Off-Topic P.S:<i>Is there any way to get the Raize/Konopka controls installed into Delphi Community Edition 10.4?</i> 🤔 I can’t use 10.4 CE for my primary project, because it makes extensive use of Raize. So I have to continue using 10.1 Berlin….