Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: DBGrid Unselected State



Permlink Replies: 7 - Last Post: Sep 24, 2017 1:49 PM Last Post By: Wanli Ma
Wanli Ma

Posts: 21
Registered: 12/6/05
DBGrid Unselected State
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 23, 2017 4:19 PM
When DGGrid is bound to a live query or an in memory table, it always has one row active, marked by an indicator arrow and highlighted row. Even there are two boundary conditions BOF and EOF, there is still always an active row. Is there a way to achieve an unselected state? i.e. RecNo = -1, so there is no row showing indicator arrow and highlighted background. Thanks!
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: DBGrid Unselected State
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 23, 2017 5:56 PM   in response to: Wanli Ma in response to: Wanli Ma
Wanli Ma wrote:
When DGGrid is bound to a live query or an in memory table, it always has one row active, marked by an indicator arrow and highlighted row. Even there are two boundary conditions BOF and EOF, there is still always an active row. Is there a way to achieve an unselected state? i.e. RecNo = -1, so there is no row showing indicator arrow and highlighted background. Thanks!

With TDataset's there is always an active row (RecNo).

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)
Wanli Ma

Posts: 21
Registered: 12/6/05
Re: DBGrid Unselected State
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 23, 2017 8:26 PM   in response to: Jeff Overcash (... in response to: Jeff Overcash (...
Thanks Jeff. Guess it cannot be done. I have a DBGrid showing rows of descriptions. When user clicks on a row, display panel shows the corresponding blob content for updating. When user clicks on the New button, however, I would like anything reminding user of an existing active row gone. So it is more clear to see if the input is in Insert or Update mode.
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: DBGrid Unselected State
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 24, 2017 1:01 AM   in response to: Wanli Ma in response to: Wanli Ma
Wanli Ma wrote:

Thanks Jeff. Guess it cannot be done. I have a DBGrid showing rows
of descriptions. When user clicks on a row, display panel shows the
corresponding blob content for updating. When user clicks on the New
button, however, I would like anything reminding user of an existing
active row gone. So it is more clear to see if the input is in
Insert or Update mode.

This should be happening. In the new row the blob field is null and the
content of the associated memo should be cleared.
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: DBGrid Unselected State
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 24, 2017 4:28 AM   in response to: Wanli Ma in response to: Wanli Ma
Wanli

Three alternatives:

1. make dbgrid invisible
2. disable dbgrid (changes appearance a bit)
3.gray grid out (there was a thread about graying out controls recently)

Roy Lambert

Wanli Ma

Posts: 21
Registered: 12/6/05
Re: DBGrid Unselected State
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 24, 2017 6:55 AM   in response to: Roy Lambert in response to: Roy Lambert
Thanks, Roy. I now have something very close to what I need. I will post it here for further suggestions and also wish someone can help fix the last issue. As to Lajos suggestion, my display panel is not any of the real db controls for the content is real blob, the field is like a pack rat.

I added a new property ShowActiveRowHighlighting. override DrawCell and DrawColumnCell. When ShowActiveRowHighlighting is false, it removes active row highlighting. The only remaining issue is the gdGradient is lost for the indicator column.

TDBGrid = class(Vcl.DBGrids.TDBGrid)
protected
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
procedure DrawColumnCell(const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); override;
public
ShowActiveRowHighlighting: Boolean;
end;

procedure TDBGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState);
begin
if (ACol = 0) and Self.ShowActiveRowHighlighting then
begin
Canvas.Brush.Color := TForm(Owner).Color;
Canvas.FillRect(ARect);
DrawEdge(Canvas.Handle, ARect, BDR_RAISEDOUTER, BF_FLAT);

Exit;
end
else
begin
inherited DrawCell(ACol, ARow, ARect, AState);
end;
end;

procedure TDBGrid.DrawColumnCell(const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var TextColor, BackColor: TColor;
begin
if Self.ShowActiveRowHighlighting then
begin
if (gdFocused in State) or (gdSelected in State) then
begin
TextColor := clBlack;
BackColor := clWhite;
end
else
begin
TextColor := clBlack;
BackColor := clWhite;
end;

Self.Canvas.Font.Color := TextColor;
Self.Canvas.Brush.Color := BackColor;

Self.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end
else
begin
inherited DrawColumnCell(Rect, DataCol, Column, State);
end;
end;
Krzysztof Szyszka

Posts: 78
Registered: 3/4/04
Re: DBGrid Unselected State
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 24, 2017 12:52 PM   in response to: Wanli Ma in response to: Wanli Ma
Thanks, Roy. I now have something very close to what I need. I will post it here for further
suggestions and also wish someone can help fix the last issue. As to Lajos suggestion, my display
panel is not any of the real db controls for the content is real blob, the field is like a pack
rat.

I added a new property ShowActiveRowHighlighting. override DrawCell and DrawColumnCell. When
ShowActiveRowHighlighting is false, it removes active row highlighting. The only remaining issue
is the gdGradient is lost for the indicator column.

It should suffice to override function TCustomDBGrid.HighlightCell and return False.

--
pozdrowienia
Krzysztof Szyszka, X-Files Software
Developer of X-DBGrid Component
Embarcadero Technology Partner
http://www.x-files.pl/

Wanli Ma

Posts: 21
Registered: 12/6/05
Re: DBGrid Unselected State
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 24, 2017 1:36 PM   in response to: Krzysztof Szyszka in response to: Krzysztof Szyszka
Thanks, Krzysztof. I gave a try to your solution. It does offer another simpler way of removing highlight from normal cells. But it does not remove the indicator arrow. My current overriding DrawCell conditionally takes out the draw arrow bitmap code. While it works, for some reason, the indicator column now also loses the gradient, thus has an inconsistent look. Here DBGrid.DrawyingStyle := gdsGradient.

I also tried adding at DrawCell:

GradientFillCanvas(Canvas, clBtnHighlight, clBtnFace, ARect, gdVertical);

But this gradient is not the same gradient.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02