Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

A cell in blue is shown in a StringGrid control, but I don't want so

Posted on 1998-10-03
15
Medium Priority
?
171 Views
Last Modified: 2011-09-20
Hi all experts again!

I have some StringGrid controls in my form which when I run the application, show the first cell in blue. I'm trying to modify selection properties, but I cannot make that blue square to disappear. Any suggestion?

Thanks in advance
Jaime
0
Comment
Question by:skel
[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
  • 5
  • 4
  • 4
  • +1
15 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1341603
hi skel,

set gridoption : goDrawFocusSelected to False.

Zif.
0
 
LVL 2

Expert Comment

by:mikepj
ID: 1341604
StringGrid1.Options:=StringGrid1.Options+[goDrawFocusSelected]
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341605
Hello....Everyone could answer that.... but Zif answered it first, so if skel likes it he has to give the credit to Zif

//Vik
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Expert Comment

by:mikepj
ID: 1341606
Quite right--it is an easy question.  However, like your answer to my question, Viktor, if the answer isn't spelled out better, it can be useless for a beginner.  I spelled it out so he could actually use the answer even if he didn't know very much.  I figured he wanted to do this programmatically.  I don't much care who gets the points--I certainly don't need them.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341607
Well, I don't know if someone is a beginner and I ain't planning to ask.... When I was one of them no one asked me...."Are you a beginnir or not??" .... If you don't understand something about the answer you ask furthur questiuons until you are sure you understand...That's the purpose of E-E

btw- If skel didn't understand theanswer he would ask for some code...or something....

//Viktor
0
 

Author Comment

by:skel
ID: 1341608
Hi all!! thanks for the answers... I have these options "TRUE" in Grid Options...

[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine]

the rest is FALSE, but when I run the application... it's still showing the blue square in the grid.

I tried with all options FALSE, and the result is the same. The control is TStringGrid.

What's the problem?
Jaime
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341609
Here is a solution.....

SG = StringGrid

In OnDrawCell() of the string grid do this....

procedure TForm1.SGDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
    if not((ACol = 0) and (ARow = 0)) then
        SG.Canvas.FillRect(Rect);
end;

btw- I hope you remmember about the credit if this helps ya

Regards,
Viktor Ivanov
0
 

Author Comment

by:skel
ID: 1341610
It didn't worked :(
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341611
What didn't go well?? Tell me any error messages or something...so I can help you firthur more...

Viktor
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341612
If you are using Delphi 3 I think that you need to use Col Row instead of ACol ARow....I'm not sure though...

//Viktor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1341613
Hi skel et al,

Viktornet, just tried your code out on D3. It's correct about Col and Row but the bue box keeps there the first time (when clicked it goes away), its like the other solutions.

This works (I hope)

procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
  Rect: TRect; State: TGridDrawState);
  var HoldColor : TColor;
begin
 with sender as TStringGrid do begin
  if (gdSelected in State) then begin
   HoldColor :=Canvas.Brush.Color;
   Canvas.Brush.Color := (Sender as TStringGrid).Color;
   Canvas.FillRect(Rect);
   Canvas.Brush.Color := HoldColor;
  end;
 end;
end;

Regards, Zif.
0
 

Author Comment

by:skel
ID: 1341614
Hi... It finally works with ZifNab solution, but I didn't use HoldColor variable and sentences associated with it. I got the effect that when the control looses focus, the actual selected cell remains in white, that's good for my application. How can I grade Zif answer instead of mikepj one which was the original answer? I don't know where to change name of the graded person.

Viktornet: I realized immediately that I had to change ACol into Col and ARow into Row.... when I said it didn't work I refered that it didn't do what I wanted to do, not that it didn't compiled.

Thanks a lot for your answers
Jaime

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1341615
Hi skel,

I wasn't already sure if HoldColor was needed, but I thought it couldn't to anything wrong, besides it was late and I was to lousy to try it without (sorry).

I'm glad it works now.

If you want to give the points to me, then you've to reject the answer of mikepj (sorry mikepj). Then I can answer the q'n and then you can grade it.

Regards, Zif.
0
 

Author Comment

by:skel
ID: 1341616
Hi Zif.. you can answer the question now :)

thanks for all and bye
Jaime
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1341617
Hi Jaime,

Q'n becomes answered... now :

procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
  Rect: TRect; State: TGridDrawState);
  var HoldColor : TColor;
begin
 with sender as TStringGrid do begin
  if (gdSelected in State) then begin
   HoldColor :=Canvas.Brush.Color;
   Canvas.Brush.Color := (Sender as TStringGrid).Color;
   Canvas.FillRect(Rect);
   Canvas.Brush.Color := HoldColor;
  end;
 end;
end;

Use of HoldColor isn't necessary.

Zif.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

721 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