View Issue Details

IDProjectCategoryView StatusLast Update
0001358JEDI VCL00 JVCL Componentspublic2004-04-22 01:10
ReporterfbcAssigned Touser72 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0001358: JvDBGrid OnGetCellParams var BackGround
DescriptionBackround color in this event does not reflect the color of a selected cell (RowSelect := true) but just the background color of the control.
Additional InformationI use this event to suppress unwanted data (i.e. 0 dates, shown as 31/12/1899) by changing the font.color to be the same as background; since Background is not changed, I end up with '31/12/1899' in white on the selected row.
TagsNo tags attached.

Activities

user72

2004-02-23 08:18

  ~0003010

I would suggest using OnGetText and OnSetText instead. That's what they are for.

fbc

2004-02-23 23:11

reporter   ~0003017

Last edited: 2004-02-23 23:25

OnGetText is not a puplished event in my JvDBGrid.

Here is a fix for the problem (marked FBC):
(Please also look at the part marked ????? what is the purpose, ABack is never used)

procedure TJvDBGrid.GetCellProps(Field: TField; AFont: TFont;
  var Background: TColor; Highlight: Boolean);
var
  AColor, ABack: TColor;

  function IsAfterFixedCols: Boolean;
  var
    I: Integer;
  begin
    Result := True;
    for I := 0 to FixedCols - 1 do
      if Columns.Items[I].FieldName = Field.FieldName then
      begin
        Result := False;
        Break;
      end;
  end;

begin
  if (FCurrentDrawRow >= FixedRows) and Odd(FCurrentDrawRow + FixedRows) and
    (FAlternateRowColor <> clNone) and (FAlternateRowColor <> Color) and
    IsAfterFixedCols then
    Background := AlternateRowColor;

  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  // FBC: New place for Highlight code
  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  // Lionel
  if Highlight then
  begin
    AFont.Color := clHighlightText;
    Background := clHighlight;
  end;
  // End Lionel
    
  if Assigned(FOnGetCellParams) then
    FOnGetCellParams(Self, Field, AFont, Background, Highlight)
  else if Assigned(FOnGetCellProps) then
  begin
    // ???????? Strange code, what is ABack doing ??????????
    if Highlight then
    begin
      AColor := AFont.Color;
      FOnGetCellProps(Self, Field, AFont, ABack);
      AFont.Color := AColor;
    end
    else
      FOnGetCellProps(Self, Field, AFont, Background);
  end;
  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  // FBC: Remove this part, overwrites any changes done in events
  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  // Lionel
  
  //if Highlight then
  //begin
  // AFont.Color := clHighlightText;
  // Background := clHighlight;
  //end;
  
  // End Lionel
end;

regards
Flemming

edited on: 02-23-04 23:25

user72

2004-02-24 05:04

  ~0003037

>OnGetText is not a puplished event in my JvDBGrid.
Sorry, they are published in the TField class, not DBGrid

>(Please also look at the part marked ????? what is the purpose,
>ABack is never used)
It's just a dummy parameter (it's a var, so required) when Highlight is true. Neither the font color nor the background color is used from OnGetCellProps in this case.

> Here is a fix for the problem (marked FBC):
Thanks, will add to CVS

user72

2004-02-24 05:06

  ~0003038

BTW, wouldn't it be better to just change the code to:

  if Assigned(FOnGetCellParams) then
    FOnGetCellParams(Self, Field, AFont, Background, Highlight)
  else if Assigned(FOnGetCellProps) then
    FOnGetCellProps(Self, Field, AFont, Background);

Whouldn't it be nice to allow to change the font and background color even if Highlight is true? Can you see any side-effects of allowing it?

fbc

2004-02-24 05:21

reporter   ~0003039

I can't see how there could be a problem, there is no law saying you HAVE to write code in the event-procedure :-)
BTW: Do we need both GetCellParams and GetCellProps, they do (almost) the same thing and are called from the same place.

Flemming

user72

2004-02-24 06:13

  ~0003040

OnGetCellProps is marked as obsolete but I am a bit hesitant removing it...

fbc

2004-02-24 06:30

reporter   ~0003042

I can understand that. Let's make the other changes, and close this issue.

user72

2004-02-24 08:38

  ~0003044

Fixed in CVS

Issue History

Date Modified Username Field Change
2004-02-23 02:11 fbc New Issue
2004-02-23 08:18 user72 Note Added: 0003010
2004-02-23 23:11 fbc Note Added: 0003017
2004-02-23 23:25 fbc Note Edited: 0003017
2004-02-24 05:04 user72 Note Added: 0003037
2004-02-24 05:04 user72 Status new => assigned
2004-02-24 05:04 user72 Assigned To => user72
2004-02-24 05:06 user72 Note Added: 0003038
2004-02-24 05:12 user72 Status assigned => feedback
2004-02-24 05:21 fbc Note Added: 0003039
2004-02-24 06:13 user72 Note Added: 0003040
2004-02-24 06:30 fbc Note Added: 0003042
2004-02-24 08:38 user72 Status feedback => resolved
2004-02-24 08:38 user72 Resolution open => fixed
2004-02-24 08:38 user72 Note Added: 0003044
2004-04-22 01:10 user72 Status resolved => closed