[Webinar] Learn how to a build a cloud-first strategyRegister Now


StringGrid remove rectangle...

Posted on 2004-11-30
Medium Priority
Last Modified: 2010-04-05
I'm using StringGrid. How can I remove rectangle around the selected cell, but not in fixed row.If I use stringgrid1.DefaultDrawing:=false i lost 3d efect in fixed row.
Thank you.
Question by:nikola_mk
1 Comment
LVL 17

Accepted Solution

Wim ten Brink earned 200 total points
ID: 12718349
I've checked the sourcecode in Delphi 5... You can't!... :-(
You will have to draw the contents yourself. But if you disable DefaultDrawing, set GridLineWidth to 0 and just want to keep it simple, you could use this:

procedure TFormMain.StringGrid1DrawCell( Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState );
  if ( ACol < StringGrid1.FixedCols ) or ( ARow < StringGrid1.FixedRows ) then begin
    StringGrid1.Canvas.Pen.Color := clBtnText;
    StringGrid1.Canvas.Brush.Color := clBtnFace;
    StringGrid1.Canvas.FillRect( Rect );
    DrawEdge( StringGrid1.Canvas.Handle, Rect, EDGE_RAISED, BF_RECT or BF_ADJUST );
  else begin
    StringGrid1.Canvas.Pen.Color := clWindowText;
    StringGrid1.Canvas.Brush.Color := clWindow;
    StringGrid1.Canvas.FillRect( Rect );
  StringGrid1.Canvas.TextRect( Rect, Rect.Left + 2, Rect.Top + 2, StringGrid1.Cells[ ACol, ARow ] );

It will draw the nice 3D edge and you can actually choose which edge you like. The BF_ADJUST is there because the GridLineWidth is 0. (It adjusts the rectangle borders by making it one pixel smaller on all sides.) If you do want those gridlines, just remove BF_ADJUST else you will get a thick border.

Of course, if you use
   DrawEdge( StringGrid1.Canvas.Handle, Rect, EDGE_RAISED, BF_RECT or BF_ADJUST );
for ALL the cells, they will all get a nice 3D view.

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question