Board index » delphi » DBGrid Selectedrows

DBGrid Selectedrows


2006-05-31 04:57:47 PM
delphi115
Hi
I want to thave he selected row in a DBgrid in color. I try to work with
selectedrows but couldn't achieve what I wanted. To have the selectedrows
highlighted in some way.
Someone has an idee?
thanks
regards to all
claude
 
 

Re:DBGrid Selectedrows

Hello Claude,
You can use the OnDrawDataCell on the TDBGrid component.
You can use something like this for example:
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
if DBGrid1.SelectedRows.CurrentRowSelected then
begin
DBGrid1.Canvas.Font.Color := clRed; // Font color
DBGrid1.Canvas.Brush.Color := clLime; // Background color
DBGrid1.Canvas.FillRect(Rect);
end;
DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;
Good Luck
Marco Maes
"Claude Lec" <XXXX@XXXXX.COM>schreef in bericht
Quote
Hi

I want to thave he selected row in a DBgrid in color. I try to work with
selectedrows but couldn't achieve what I wanted. To have the selectedrows
highlighted in some way.
Someone has an idee?
 

Re:DBGrid Selectedrows

Thanks Marco
I have a try
claude
"Marco Maes" <XXXX@XXXXX.COM>a écrit dans le message de news:
447d87a6$XXXX@XXXXX.COM...
Quote
Hello Claude,

You can use the OnDrawDataCell on the TDBGrid component.

You can use something like this for example:

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
if DBGrid1.SelectedRows.CurrentRowSelected then
begin
DBGrid1.Canvas.Font.Color := clRed; // Font color
DBGrid1.Canvas.Brush.Color := clLime; // Background color
DBGrid1.Canvas.FillRect(Rect);
end;
DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;

Good Luck
Marco Maes

"Claude Lec" <XXXX@XXXXX.COM>schreef in bericht
news:XXXX@XXXXX.COM...
>Hi
>
>I want to thave he selected row in a DBgrid in color. I try to work with
>selectedrows but couldn't achieve what I wanted. To have the selectedrows
>highlighted in some way.
>Someone has an idee?


 

Re:DBGrid Selectedrows

You can set the "Options"->"dgMultiSelect" True!
 

Re:DBGrid Selectedrows

Hi all!
I have to do some stuff in the OnDrawColumnCell depending on the Selected
state of the row. How can I know if a row is selected without making it the
current row?
T.I.A.
Ines
 

Re:DBGrid Selectedrows

Inés Fernández writes:
Quote
Hi all!
I have to do some stuff in the OnDrawColumnCell depending on the Selected
state of the row. How can I know if a row is selected without making it the
current row?

T.I.A.

Ines


if(State == gdSelected) {
//Make it pretty :)
}
DC