Solved

how to make stringgrid's selection invisible?

Posted on 1998-07-30
11
1,308 Views
Last Modified: 2010-05-18
When I click a stringgrid's cell,it will select the cell,and  the cell will turn blue.Now I don't want the cell turn blue.how can I do it?
0
Comment
Question by:nhomc
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359109
Hi nhomc,

 Grid1.Options := Grid1.Options - [goDrawFocusSelected];

Regards, Zif.

It's worth looking at these free components :

 TStringGrid of RX-Lb (http://rx.demo.ru)
 THyperGrid/TSuperGrid of Marly (http://www.pablop.demon.co.uk/)
0
 

Author Comment

by:nhomc
ID: 1359110
ZifNab:
   I'm sorry,it doesn't work,in my program,the goDrawFocusSelected option sets false,so when I use Grid1.Options := Grid1.Options - [goDrawFocusSelected],it has no change.But when I click another object that is  not in the stringgrid,the blue rectangle in the selected cell appears,
Now I  want the blue rectangle doesn't appear forever,how can I do that?
0
 

Author Comment

by:nhomc
ID: 1359111
ZifNab:
   I'm sorry,it doesn't work,in my program,the goDrawFocusSelected option sets false,so when I use Grid1.Options := Grid1.Options - [goDrawFocusSelected],it has no change.But when I click another object that is  not in the stringgrid,the blue rectangle in the selected cell appears,
Now I  want the blue rectangle doesn't appear forever,how can I do that?
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 10

Expert Comment

by:viktornet
ID: 1359112
Do the same thing as ZifNab told you, but do it before you compile the program not in run time like so....Before you run the app: Select the StringGrid, Go to its properties and double click on Options, then choose  goDrawFocusSelected := False;.....That's before you run your app, if you want to change that in run-time, just enter this somewhere...
Grid1.Options := Grid1.Options + [goDrawFocusSelected];
That's all you need to do...

Regards,
Viktor Ivanov

0
 
LVL 2

Expert Comment

by:kjteng
ID: 1359113
Set the defaultDrawing property to false and write your own onDrawCell procedure, this is the most flexible way as you it enable you to choose us the color you like. For example, you may change the cell text into read color (white backgroup) when the grid is not in focus. You can also subclass TstringGrid and overwrite the drawCell procedure.
Let me know if you need sample code. I will modify my code for you if need be.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1359114
What's wrong with my answer?I tried it and it works????

Regards,
Viktor Ivanov
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1359115
Matvey: using your method, the selected cell would be highlighted again when you tab to other component in the same form ie when the grid is not in focus.

nhomc:
{
Set the defaultDrawing property to false and write your own onDrawCell procedure as follows:
}
procedure TForm1.Grid1DrawCell(Sender: TObject; Col, Row: Longint;  Rect: TRect; State: TGridDrawState);
var str0: array[0..255] of char; textAlign: word;
begin
  with grid1.canvas do begin
    if ( gdFixed in state)  then
      brush.color:= grid1.fixedColor
    else if ( gdSelected in State) then begin
      brush.color:= clWindow;
      if ( grid1.focused) then
        grid1.canvas.font.color:= clBlue
      else
        grid1.canvas.font.color:= clRed;
    end else begin
      font.color:= clBlack;
      brush.color:= clWindow;
    end;
    strPCopy( str0, grid1.cells[ col, row] );
    fillRect( rect);
    textAlign:= DT_LEFT or DT_SINGLELINE OR DT_VCENTER;
    drawText( handle, str0, -1, rect, textAlign);
  end;
end;
0
 

Author Comment

by:nhomc
ID: 1359116
  I'm sorry,it doesn't work,in my program,the goDrawFocusSelected option sets false,so when I use Grid1.Options := Grid1.Options - [goDrawFocusSelected],it has no change.But when I click another object that is  not in the stringgrid,the blue rectangle in the selected cell appears,
Now I  want the blue rectangle doesn't appear forever,how can I do that?
0
 

Author Comment

by:nhomc
ID: 1359117
When I set goDrawFocusSelected to false,if I click the stringgrid, the blue rectangle doesn't appear in the stringgrid.
But when I click another object that is not in the stringgrid,
such as a button,the blue rectangle appear in the stringgrid.
Now I want the blue rectangle doesn't appear forever,
How can I do It?

0
 
LVL 3

Accepted Solution

by:
vladika earned 100 total points
ID: 1359118
Try it

Set DefaultDraw=TRUE (I mean do not change it)
and write OnDrawCell handler

procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
  Rect: TRect; State: TGridDrawState);
var S: string;
begin
  if not StringGrid1.DefaultDrawing then Exit;
  if not (gdFixed in State) then
  begin
    StringGrid1.Canvas.Font := StringGrid1.Font;
    StringGrid1.Canvas.Brush.Color := StringGrid1.Color;
    StringGrid1.Canvas.FillRect(Rect);
    S := StringGrid1.Cells[Col, Row];
    ExtTextOut(StringGrid1.Canvas.Handle, Rect.Left + 2, Rect.Top + 2, ETO_CLIPPED or
      ETO_OPAQUE, @Rect, PChar(S), Length(S), nil);
  end;
end;

0
 
LVL 2

Expert Comment

by:kjteng
ID: 1359119
nhomc: did you try my code? what's wrong with it?
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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