Link to home
Start Free TrialLog in
Avatar of skel
skel

asked on

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

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
Avatar of ZifNab
ZifNab

hi skel,

set gridoption : goDrawFocusSelected to False.

Zif.
StringGrid1.Options:=StringGrid1.Options+[goDrawFocusSelected]
Hello....Everyone could answer that.... but Zif answered it first, so if skel likes it he has to give the credit to Zif

//Vik
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.
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
Avatar of skel

ASKER

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
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
Avatar of skel

ASKER

It didn't worked :(
What didn't go well?? Tell me any error messages or something...so I can help you firthur more...

Viktor
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
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.
Avatar of skel

ASKER

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

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.
Avatar of skel

ASKER

Hi Zif.. you can answer the question now :)

thanks for all and bye
Jaime
ASKER CERTIFIED SOLUTION
Avatar of ZifNab
ZifNab

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial