Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

dbGrid Row Highlighting

Posted on 1998-06-16
7
Medium Priority
?
566 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 140 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

916 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