I'm trying to replace True/False with Yes/No in a DBGrid. The code below almost works:
procedure TDatamodule1.DBGridDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
sText : String;
begin
if (UpperCase(Column.Field.FieldName) = UpperCase('Approved')) or
(UpperCase(Column.Field.FieldName) = UpperCase('Obsolete')) then
begin
if Column.Field.Value = True then
sText := 'Yes'
Else
If Column.Field.Value = False Then
sText := 'No'
Else
sText := '';
(Sender as TDBGrid).Canvas.FillRect(Rect);
(Sender as TDBGrid).Canvas.TextRect(Rect, Rect.Left+3, Rect.Top+2, sText);
end;
end;
This appeared to work until I started using the keyboard cursor keys to move around the grid. The cell that has the focus always has both True and Yes or False and No drawn on top of each other. How do I prevent the default True/False label from being drawn on the cell that has focus? All other cells of the grid are perfect.
Edit: I failed to mention that the grid is set to Readonly and I've noticed the problem is with both selected and focused. Thanks in advance.
I resolved my issue with a lot of trial and error. First, in the DBGrid components I set dgEditing to false as it was unnecessary (my grid is readonly). This prevents the user from getting the cell into the focused mode. Second, I set DefaultDrawing to False. I updated my DBGridDrawColumnCell procedure as follows: