I wish to color my DBGrid as for the following schema:
- All of the DBGrid with black cahracters on a white background
- If the user goes into edit mode, I would like the cell the user wants to
edit to get a yellow background and the entire ROW a grey background. The
cell should keep its yellow background while the user is typing.
I have written the following procedure to realize what above, but
unfortunately it doesn't work as expected: in fact when entering the edit
mode (clicking a button):
- the ROW doesn't get its grey background,
- the yellow background is on the first cell of the row (and this may be
right), but as soon as one starts typing, the background turns to white..
Can you understand why or give me a suggestion ?
with Sender as TDBGrid do
begin
if dgRowSelect in Options then
// dgRowSelect ON = DBGrid in Browse mode
DefaultDrawColumnCell(Rect, Datacol, Column, State)
else
begin
// dgRowSelect OFF = DBGrid in Edit mode
if State = [gdFocused, gdSelected] then
begin
// yellow background on the cell in edit
Canvas.Brush.Color := clYellow;
Canvas.Font.Color := clBlack;
end else
begin
// grey background on the row of the cell in edit
Canvas.Brush.Color := clGrey;
Canvas.Font.Color := clBlack;
end;
DefaultDrawColumnCell(Rect, Datacol, Column, State);
end;
end;


|