Solved

how to make stringgrid's selection invisible?

Posted on 1998-07-30
11
1,298 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

26 Experts available now in Live!

Get 1:1 Help Now