Solved

dbGrid Row Highlighting

Posted on 1998-06-16
7
547 Views
Last Modified: 2010-08-05
I need to visually indicate to the user what the current row is on a dbGrid (beyond the triangle indicator).  However, I must keep the sensitivity to what column is selected for various sort and other functionalities.

Delphi has the Rowselected option but at the expense of individual column sensitivity.

How can I have the best of both worlds?
0
Comment
Question by:swig
[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
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1353275
Swig,

   Would highlighting the entire row (or even bolding all text in it) and then changing the color of the text in the selected column work? If so there are several ways to change the display format for rows and / or cells in a dbGrid depending on data values or the selected rows. Let me know if this is what your looking for and I'll post some owner-drawn dbGrid code for ya to look at.

Good luck with your project!
Pegasus
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353276
Swig,

 The best way to do it is to choose a color for your selected rows, and then use the inverted color for your 'active' row. For this you've the make an owner-drawn dbgrid, like Pegasus says. You can also look at the dbgrid of the freeware rx library. (url : rx.demo.ru)

regards, Zif.
0
 

Author Comment

by:swig
ID: 1353277
Wow, I appreciate the response, guys...

I like the idea of bolding the text for the entire row (keeping the selected column highlighted).  However, I am open to other ideas.

The users that are working with this grid are dealing with having to assess the data presented in each row, process it and scroll to the next row in a vary rapid manner.  As a result, I cannot compromise how crisp the data in the row shows up - if you understand what I mean.

Thanks again for your interest/help
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 70 total points
ID: 1353278
Swig,

 Here is some code pasted out of my application that turns a given cell red depending on it's value. Notice the declarations. This code was modified from that supplied in the Delphi Programming Problem Solver by Rugenking, highly recommended. Let me know if I can be of further assistance!

Pegasus

* * *

  private
    { Private declarations }
    {$IFDEF Win32}
    procedure dbgContractEntityDrawColumnCell(Sender: TObject;
      const Rect: TRect; Datacol: Integer; Column: TColumn;
      State: TGridDrawState);
    {$ENDIF}
    procedure Drawfield(const Value: String; const Rect: TRect;
      vCanvas: TCanvas; vFont: TFont; vAlignment: TAlignment);

{======================================================================}


procedure TfrmData_Maint.FormCreate(Sender: TObject);
begin
sDataObjectNames := TStringList.Create;

{$IFDEF Win32}
dbgContractEntity.OnDrawDataCell := NIL;
dbgContractEntity.OnDrawColumnCell := dbgContractEntityDrawColumnCell;
{$ENDIF}
end;

{======================================================================}
procedure TfrmData_Maint.dbgContractEntityDrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
begin
WITH Sender AS TDBGrid, Datasource.Dataset DO
  Begin
   If DM_DATARISK.tblCounterparty.FieldByname('CP_Default_CE').Value =
      FieldByName('RCE_CONTRACT_ENTITY').AsString then
      Drawfield(Field.DisplayText, Rect, Canvas, Canvas.Font, Field.Alignment);
  end;
end;
{======================================================================}



{$IFDEF Win32}
procedure TfrmData_Maint.dbgContractEntityDrawColumnCell(Sender: TObject;
   const Rect: TRect; Datacol: Integer; Column: TColumn;
   State: TGridDrawState);
   begin
    With Sender as TDBGrid, DataSource.DataSet DO
      Begin
   If DM_DATARISK.tblCounterparty.FieldByname('CP_Default_CE').Value =
      FieldByName('RCE_CONTRACT_ENTITY').AsString then
      Drawfield(Column.Field.DisplayText, Rect, Canvas, Column.Font, Column.Alignment);
      end;
   end;
{$ENDIF}


{======================================================================}

procedure TfrmData_Maint.DrawField(const Value: String; const Rect: TRect;
      vCanvas: TCanvas; vFont: TFont; vAlignment: TAlignment);
VAR X: Integer;
begin
X := 0;
vCanvas.Font := vFont;
vCanvas.Font.Color := clRed;
vCanvas.Font.Style := vCanvas.Font.Style + [fsBOLD];
CASE vAlignment OF
  taRightJustify: BEGIN
  SetTextAlign(vCanvas.Handle, TA_RIGHT);
  X := Rect.Right -2;
  END;
  taLeftJustify: BEGIN
  SetTextAlign(vCanvas.Handle, TA_LEFT);
  X := Rect.Left + 2;
  END;
  taCenter       : BEGIN
   SetTextAlign(vCanvas.Handle, TA_CENTER);
   X := (Rect.Right + Rect.Left) DIV 2;
   end;
end;   // end CASE
vCanvas.TextRect(Rect, X, Rect.Top+2, Value);
SetTextAlign(vCanvas.Handle, TA_LEFT);
end;

0
 

Author Comment

by:swig
ID: 1353279
Pegasus,
Sorry for the delay in getting back to you.

I am getting access violations on the call to the DrawField Procedure and I cannot figure out why.  here is a sample of what I have & how I have incorporated your suggestions...
_____________________________________________________________
  private
    { Private declarations }
    procedure DrawField(const Value: String; const Rect: TRect;
              vCanvas: TCanvas; vFont: TFont; vAlignment: TAlignment);

_________________________________________________________________

procedure TfrmIVwr.DBGridX1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
var
  s : string;
begin
  with TDbGrid(Sender) do begin
  .
  .
  .
   else if (datasource.dataset.fieldByName('watch_flag').AsString='W') then begin
     DrawField(column.Field.DisplayText, Rect, Canvas, Column.Font, Column.Alignment);
     Canvas.Draw((rect.left+rect.right) div 2 - 6, (rect.bottom+rect.top) div 2 -6,             imgWatch.picture.graphic);
      end
  .
  .
  .
  end;
end;
___________________________________________________
procedure TfrmIVwr.DrawField(const Value: String; const Rect: TRect;
   vCanvas: TCanvas; vFont: TFont; vAlignment: TAlignment);
var
   x: integer;
begin
     x:= 0;
     vCanvas.Font := vFont;
     vCanvas.Font.Color := clRed;
     vCanvas.Font.Style := vCanvas.font.Style + [fsBold];
     CASE vAlignment OF
       taRightJustify: begin
          SetTextAlign(vCanvas.Handle, TA_RIGHT);
          x:=Rect.Right - 2;
       end;
       taLeftJustify: begin
          SetTextAlign(vCanvas.Handle, TA_LEFT);
          x:=Rect.Right + 2;
       end;
       taCenter: begin
          SetTextAlign(vCanvas.Handle, TA_CENTER);
          x:=(Rect.Right + Rect.Left) DIV 2;
       end;
     END; //End Case
     vCanvas.TextRect(Rect, x, Rect.Top + 2, Value);
     SetTextAlign(vCanvas.Handle, TA_LEFT);
end;
0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1353280
Swig,

  Double-check the {Private} declarations, looks like your missing the {$IFDEF} directives and the DrawColumnCell procedure/declarations. Let me know & good luck!

Pegasus
0
 

Author Comment

by:swig
ID: 1353281
Pegasus,
Remember Me?  I have been away from the office.  Sorry for the delay.  I have included the declarations and directives to be exactly as you described, but I still get the access violations as before.  

Don't mean to drag this issue on.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

617 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