?
Solved

how to make stringgrid's selection invisible?

Posted on 1998-07-30
11
Medium Priority
?
1,396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

719 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