Home › Forums › Konopka Signature VCL Controls (formerly Raize Components) › TRzDBGrid.QuickCompare
Tagged: TRzDBGrid QuickCompare
- This topic has 7 replies, 2 voices, and was last updated 2021-09-12 at 10:15 pm by Peter Dzomlija.
-
AuthorPosts
-
-
August 27, 2021 at 1:19 pm #2577
I use the TRzDBGrid.QuickCompare property do display records marked as “Invalid” in an alternate color.
However, my particular needs require 3 drawing states for the records in my data:
- Normal (Font Color “clWindowText”)
- Invalid (Font Color “clRed”)
- Requires Attention (Font Color “clGreen”)
Is there a way to use TRzDBGrid.QuickCompare do do this?
If not, then perhaps TRzDBGrid can be further updated do allow for multiple “QuickCompare” entries, in a fashion similar to TRzDBGrid.Columns so that multiple compare conditions can be specified?
- This topic was modified 3 years, 3 months ago by Peter Dzomlija. Reason: Spelling Errors
-
September 3, 2021 at 2:20 am #2598
Hi Peter,
The QuickCompare functionality is designed to test a condition for each row and if the condition is met, the row is colored using the QuickCompare.Color value. As such, it really is not designed to handle what you are suggesting.
Allowing multiple conditions would be a way to handle that, but that would require changing the QuickCompare property to a collection. It is certainly something that you should request from Embarcadero. (BTW, I’m trying to find out from Embarcadero, what is the property way customers can submit bug reports and enhancement requests for the KSVC. I’ll post my findings in this forum).
As an alternative, you may be able to accomplish what you wish by handling the OnDrawColumnCell event.
Ray
-
September 3, 2021 at 2:58 am #2599
For for your response, Ray.
This is a sample use of “OnDrawColumnCell”:
It works well enough to replace the “TRUE / FALSE” displayed by Boolean fields with a checkmark glyph.
But as far as I can tell, “OnDrawColumnCell” only gives me access to the value of the field that is being drawn, and not the entire record represented by the row. So if I’m drawing a string field, I cannot check the value of a boolean field in the same record, which means I can’t change the font style to (for example) “Red, StrikeOut” or “Green, Italic” based upon the values of other fields in the same record…
Or have I missed something? 🤔
-
-
September 7, 2021 at 10:26 pm #2613
Hi Peter,
Sorry for the delay. You can get the value of other fields in the record by using the Column parameter. For example,
var GamesField: TField; begin GamesField := Column.Field.DataSet.FieldByName( 'G' ); if GamesField.Value > 50 then . . .
In this example, I have a grid displaying baseball statistics. Field G represents the number of games. I can use the Column parameter to get the field object of any other field I’m interested in. I do this to get the GamesField object, from which I can get the value and alter the appearance of the fields in that record appropriately.
Ray
-
September 11, 2021 at 12:49 am #2636
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….
-
September 12, 2021 at 10:11 pm #2664
I believe that Embarcadero has stated that the KSVC are not available for CE.
Ray
-
September 12, 2021 at 10:15 pm #2665
Pity…😑
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.