Solved

dbGrid Row Highlighting

Posted on 1998-06-16
7
511 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 70 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now