Board index » delphi » StringGrid: make Blue go away!

StringGrid: make Blue go away!

I have a StringGrid, cells populated with strings via
StringGrid.Cells[j,i]:= 'some string  '; looping through all the cells.
Default Drawing is set to true, and the DrawCell event is used to format

particular cells (namely, to draw a thick line on some of their borders,

in order to divide the SG, viewed as a matrix, into submatrices).  This
SG should simply display the data; the cells cannot be edited.  All
Options are set to false.  The problem:  when the SG appears on the
form, the "first cell" -- upper left -- is selected, and highlighted
with a ghastly blue color.  But I don't want anything selected, or
highlighted.  Just display the SG, nothing more.  In principle I don't
even want the user to be able to click on individual cells to "select"
them.  How can I shut all this down and just display the sucker?
Experimenting with different Options settings brings no relief.

Thanks, Ben Crain

 

Re:StringGrid: make Blue go away!


Hi

Quote
>Options are set to false.  The problem:  when the SG appears on the
>form, the "first cell" -- upper left -- is selected, and highlighted
>with a ghastly blue color.  But I don't want anything selected, or
>highlighted.  Just display the SG, nothing more.  In principle I don't

try this

procedure TForm1.FormActivate(Sender: TObject);
var
  t : tgridrect;
begin
  t.Left := -1;
  t.right := -1;
  t.Bottom := -1;
  t.top := -1;
  stringgrid1.selection := t;
end;

balbaro

Re:StringGrid: make Blue go away!


in the drawcell event:

with Sender as TStringgrid do begin
  if (gdSelected in State) then begin
    Canvas.Brush.Color := Color;
    Canvas.Font.Color := Font.Color;
    Canvas.TextRect(Rect, Rect.Left +2,Rect.Top +2, Cells[Col,Row]);
  end;
end;

in the onselect event:
  CanSelect := false;

Chris

Re:StringGrid: make Blue go away!


In article <38113C53.3DD7F...@bellatlantic.net>, Ben Crain

Quote
<bcr...@bellatlantic.net> writes:
> The problem:  when the SG appears on the
>form, the "first cell" -- upper left -- is selected, and highlighted
>with a ghastly blue color.  But I don't want anything selected, or
>highlighted.  Just display the SG, nothing more.

The blue appears for a selected cell. The trick is to set the cell selection
rectangle off the displayed area of the stringgrid. Do it by coding :-

  StringGrid1.Selection := TGridRect(Rect(-1, -1, -1 ,-1));

... in the form's OnCreate and in the stringgrid's OnClick event handlers.

Alan Lloyd
alangll...@aol.com

Re:StringGrid: make Blue go away!


Thanks to my respondents.  Both methods suggested above work fine.  I'm
happy with whatever works, though it seems a bit awkward that, to achieve
such a routine objective, you have to "trick" Delphi into doing what you
want.

BC

Re:StringGrid: make Blue go away!


In article <3811EBD0.6F3AC...@bellatlantic.net>, Ben Crain

Quote
<bcr...@bellatlantic.net> writes:
>Thanks to my respondents.  Both methods suggested above work fine.  I'm
>happy with whatever works, though it seems a bit awkward that, to achieve
>such a routine objective, you have to "trick" Delphi into doing what you
>want.

They are really the same solution, but Bulbaro's will leave the focus rectangle
(outline in the cell) if the user clicks on it. Putting the off-display
selection setting into the OnClick means that that focus rectangle disappears
on mouse up.

Selection is a basic behaviour of all non-disabled controls, just be thankful
its so easy to get what you want <g>

Alan Lloyd
alangll...@aol.com

Other Threads