Discussion:
String Grid - Don't want highlight when not focussed
joeblogss84
2002-05-07 01:41:18 UTC
Permalink
G'Day all,

I am sure this is simple as I can see examples of the sort of
behavior I want about the place.

When I put a TStringGrid (standard component as supplied in D5) onto
form I find that three is always a cell highlighted - even when the
grid doesn't have focus.

I have looked on the www and searched in the archive for some clue
but the terms I need to search on are so general that getting a good
match is not working for me.

Questions:
1) How can prevent the cell/row from being highlighted (blue
background) when the grid no longer has focus?
2) How can I force the grid to allow no rows? (The component forces
at least one row, at least it is for me.)

In the case of having one fixed row, which I may want, I would want
to be able to restrict the number of rows to one (just the fixed
column headers). Hoever, currently I am forced to have a row count
of 2 for a fixed row count of 1.

As I said I am sure this is simple, but I can find the property I
want.

Thanks,
Ian
Pauline M Ross
2002-05-07 07:37:46 UTC
Permalink
On Tue, 07 May 2002 01:41:18 -0000, "joeblogss84"
Post by joeblogss84
1) How can prevent the cell/row from being highlighted (blue
background) when the grid no longer has focus?
I've never needed this, but one of the Options (goDrawFocusSelected)
seems to switch the highlight colour on and off.
Post by joeblogss84
2) How can I force the grid to allow no rows? (The component forces
at least one row, at least it is for me.)
There must be at least one row. I 'hide' the unwanted row by making
the cell colour the same as the grid colour and suppressing the grid
lines:

Grid.Options := Grid.Options - [goVertLine, goHorzLine];

By the way, if you have any fixed rows, they get unfixed when you have
just 1 row (there must always be one *scrolling* row).
--
Regards,

Pauline Ross
Ross Software
www.ross-software.co.uk
joeblogss84
2002-05-07 13:16:21 UTC
Permalink
Post by Pauline M Ross
On Tue, 07 May 2002 01:41:18 -0000, "joeblogss84"
Post by joeblogss84
1) How can prevent the cell/row from being highlighted (blue
background) when the grid no longer has focus?
I've never needed this, but one of the Options (goDrawFocusSelected)
seems to switch the highlight colour on and off.
Thanks for the reply but...

For me this I get the following behavior:
1) goDrawFocusSelected = True
A cell is always highlighted regardless of whether grid has focus
(there is always a cell shown with the (default) blue highlight).

2) goDrawFocusSelected = False
The selected cell is highlighted (in blue) when the grid does *not*
have focus, and outlined with dots when the grid does have focus.

Basically I do not want anything to show when the grid is empty. Is
it as crude as drawing blank panel over the top? Surely there is a
method of not having an annoying highlight (or grid) when the grid is
empty!

The when the grid is no longer empty, I do not want any cell to be
highlighted when the grid does *not* have focus. Is it possible to
have *no* cell selected in a grid? How is this acheived
(programatically)?

Thanks for the help,
Ian
Pauline M Ross
2002-05-07 15:49:57 UTC
Permalink
On Tue, 07 May 2002 13:16:21 -0000, "joeblogss84"
Post by joeblogss84
Basically I do not want anything to show when the grid is empty. Is
it as crude as drawing blank panel over the top? Surely there is a
method of not having an annoying highlight (or grid) when the grid is
empty!
The blank panel is one way. As I said, I get rid of the compulsory row
by making the cells the same colour as the grid background and hiding
the grid lines (although the focus rectangle remains - that has to be
got rid of as well).
Post by joeblogss84
The when the grid is no longer empty, I do not want any cell to be
highlighted when the grid does *not* have focus. Is it possible to
have *no* cell selected in a grid? How is this acheived
(programatically)?
Well, I've always needed the opposite - having selected cells
highlighted no matter where the focus is.

If you do your own cell drawing in OnDrawCell, you can control whether
the cell appears to be selected or not (regardless of whether it
actually is). The focus rectangle is more problematic. The only way I
found when experimenting to get rid of it was to force the focus
elsewhere in the OnEnter event, which may not be what you want at all!

It does seem illogical to insist on always having at least one row and
a selected cell, but there it is. It might be possible to modify
TStringGrid to behave the way you want, or you might want to look at
alternative grids. MSFlexGrid does what you want, but I don't
recommend it for a whole host of reasons.

Good luck. If you find a way round this, I'd be interested to hear
about it.
--
Regards,

Pauline Ross
Ross Software
www.ross-software.co.uk
mailgroupza
2002-05-08 20:02:29 UTC
Permalink
Hi Ian

Preventing the annoying blue cell when a cell is selected
Add the following to the OnDrawCell event

if (gdSelected in State) then
begin
AgeGrid.Canvas.Brush.Color := AgeGrid.Color;
AgeGrid.Canvas.FillRect(Rect);
SetBKMode(Handle, TRANSPARENT);
AgeGrid.Canvas.TextOut(Rect.Left, Rect.Top, AgeGrid.Cells[ACol,
ARow]);
end;

Play with state to determine when or when not you want the blue cell
displayed

Hope this helps

Regards Cao

joeblogss84
2002-05-07 14:10:24 UTC
Permalink
Post by Pauline M Ross
On Tue, 07 May 2002 01:41:18 -0000, "joeblogss84"
Post by joeblogss84
1) How can prevent the cell/row from being highlighted (blue
background) when the grid no longer has focus?
I've never needed this, but one of the Options (goDrawFocusSelected)
seems to switch the highlight colour on and off.
Thanks for the reply but...

For me this I get the following behavior:
1) goDrawFocusSelected = True
A cell is always highlighted regardless of whether grid has focus
(there is always a cell shown with the (default) blue highlight).

2) goDrawFocusSelected = False
The selected cell is highlighted (in blue) when the grid does *not*
have focus, and outlined with dots when the grid does have focus.

Basically I do not want anything to show when the grid is empty. Is
it as crude as drawing blank panel over the top? Surely there is a
method of not having an annoying highlight (or grid) when the grid is
empty!

The when the grid is no longer empty, I do not want any cell to be
highlighted when the grid does *not* have focus. Is it possible to
have *no* cell selected in a grid? How is this acheived
(programatically)?

Thanks for the help,
Ian
Loading...