StringGrid remove rectangle...

Posted on 2004-11-30
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

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    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…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now