I would like to ask if there is another way to alter the cell text without using TextOut()
? Using TextOut()
requires coordinates which I do not want to mingle into. Besides, I just want to change the text and retain everything else, like color, font, alignment, etc.
My purpose is to alter the display of text in different scenarios. For example:
- I may want to show a date field in different formats in different columns, like one column to show in
MM/yyyy
and another column to show inMM/dd/yyyy
. - I may want to display some rows with integer/float datatype with a text that says "too high" or "too low" if the figure is above or below a certain threshold.
- I may want to exchange boolean true/false with some text or numbers as I see fit.
- or perhaps, just blank some cell on certain conditions.
I understand if TDBGrid
is "editable", this would be a tough challenge to do editing. So I intend to use whatever solution in a non-editable grid. And also, I don't want to shift to TStringGrid
as I find TDBGrid
to be easy to work with a dataset.
Btw, I'm using Delphi 7.
For just leaving a certain cell blank on a certain condition, is there something that I could just issue an "exit" to skip the showing of the cell value into the cell itself?
Like:
procedure Tform1.dbgrdDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (Column.fieldname = 'total') and (column.field.value=0) then
exit
else
dbgrdsku.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;