Solved

how to make stringgrid's selection invisible?

Posted on 1998-07-30
11
1,282 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

14 Experts available now in Live!

Get 1:1 Help Now