Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBGrid Row Selected w/Vertical Scrollbar

Status
Not open for further replies.

chessdr

Programmer
Apr 22, 2002
3
US
Dear Delphi Gurus:

How do I prevent the top or bottom row in a DBGrid from being selected when the user clicks in the vertical scroll bar area?

I have the multi-select option set to TRUE, and I only want the user to see rows highlighted that they actually clicked on, not rows being automatically highlighted when they click in the vertical scroll bar area. When they click above the slider, you see the top row that fits in the window highlighted, or when they click below the slider, you see the bottom row that fits in the window highlighted.

Any help would be greatly appreciated.

Craig
 
Are you talking about the selection bar showing the "current row"?

In any case, you can control the painting of all the rows by using the OnDrawColumnCell event. There, you can check if a row is selected and repaint it without the blue background if it is:

Code:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
   with (Sender as TDBGrid) do
   begin
       if not SelectedRows.CurrentRowSelected then
       begin
           Canvas.Brush.Color := Color;
           Canvas.FillRect(Rect);
           DefaultDrawColumnCell(Rect, DataCol, Column , State);
       end;
   end;
end;
[\code]

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top