Board index » delphi » Typecasting Question: Changing a DBGrid's Cell Color when active

Typecasting Question: Changing a DBGrid's Cell Color when active

Hello all.. I am using D3 ...

My question is:
How can I highlight the selected cell in a DBGrid when it has focus by
changing it's color..

I am using these two methods below to highlight the selected controls on
a form when the user enters and exits the controls..

PreviousColor is a global variable..
ColorControlEnter() is assigned to the OnEnter() event of the controls.
ColorControlExit() is assigned to the OnExit event of the controls.

{-------------------------------------------------------}
procedure TExpensesForm.ColorControlEnter(Sender: TObject);
begin
 if Sender is TDBEdit then
  begin
   PreviousColor := TDBEdit(Sender).Color;
   TDBEdit(Sender).Color := $0080FFFF
  end;

  if Sender is TDBCombobox then
  begin
   PreviousColor := TDBComboBox(Sender).Color;
   TDBComboBox(Sender).Color := $00C08000
  end;

  if Sender is TDBMemo then
  begin
   TDBMemo(Sender).Color := $0080FFFF
  end;

 if Sender is TDBCheckBox then
  begin
   PreviousColor := TDBCheckBox(Sender).Font.Color;
   TDBCheckBox(Sender).Font.Color := clYellow;
   TDBCheckBox(Sender).Font.Style := [fsBold];
  end;

end;

{-------------------------------------------------------}
procedure TExpensesForm.ColorControlExit(Sender: TObject);
begin
 if Sender is TDBEdit then
  begin
   TDBEdit(Sender).Color := PreviousColor
  end;

  if Sender is TDBCombobox then
  begin
   TDBCombobox(Sender).Color := PreviousColor
  end;

  if Sender is TDBMemo then
  begin
   TDBCombobox(Sender).Color := PreviousColor
  end;

 if Sender is TDBCheckBox then
  begin
   TDBCheckBox(Sender).Font.Color := PreviousColor;
   TDBCheckBox(Sender).Font.Style := [];
  end;
end;

Any suggestions would be greatly appreciated!

Rkr

--

          \|||/
          /'^'\
         ( 0 0 )
-----oOOO--(_)--OOOo----------
Reid Roman
E-Mail : rkroman (at) pacbell (dot) net
Delphi Enthusiast, Hobbiest ..
TVisualBasic:=class(None);
U.S.A
------------------------------

 

Re:Typecasting Question: Changing a DBGrid's Cell Color when active


Hello all.. I am using D3 ...

My question is:
How can I highlight the selected cell in a DBGrid when it has focus by
changing it's color..

I am using these two methods below to highlight the selected controls on
a form when the user enters and exits the controls..

PreviousColor is a global variable..
ColorControlEnter() is assigned to the OnEnter() event of the controls.
ColorControlExit() is assigned to the OnExit event of the controls.

{-------------------------------------------------------}
procedure TExpensesForm.ColorControlEnter(Sender: TObject);
begin
 if Sender is TDBEdit then
  begin
   PreviousColor := TDBEdit(Sender).Color;
   TDBEdit(Sender).Color := $0080FFFF
  end;

  if Sender is TDBCombobox then
  begin
   PreviousColor := TDBComboBox(Sender).Color;
   TDBComboBox(Sender).Color := $00C08000
  end;

  if Sender is TDBMemo then
  begin
   TDBMemo(Sender).Color := $0080FFFF
  end;

 if Sender is TDBCheckBox then
  begin
   PreviousColor := TDBCheckBox(Sender).Font.Color;
   TDBCheckBox(Sender).Font.Color := clYellow;
   TDBCheckBox(Sender).Font.Style := [fsBold];
  end;

end;

{-------------------------------------------------------}
procedure TExpensesForm.ColorControlExit(Sender: TObject);
begin
 if Sender is TDBEdit then
  begin
   TDBEdit(Sender).Color := PreviousColor
  end;

  if Sender is TDBCombobox then
  begin
   TDBCombobox(Sender).Color := PreviousColor
  end;

  if Sender is TDBMemo then
  begin
   TDBCombobox(Sender).Color := PreviousColor
  end;

 if Sender is TDBCheckBox then
  begin
   TDBCheckBox(Sender).Font.Color := PreviousColor;
   TDBCheckBox(Sender).Font.Style := [];
  end;
end;

Any suggestions would be greatly appreciated!

Rkr
--

          \|||/
          /'^'\
         ( 0 0 )
-----oOOO--(_)--OOOo----------
Reid Roman
E-Mail : rkroman (at) pacbell (dot) net
Delphi Enthusiast, Hobbiest ..
TVisualBasic:=class(None);
U.S.A
------------------------------

Other Threads