Solved

Excel style memo indicator in dbGrid

Posted on 2003-11-12
10
550 Views
Last Modified: 2010-04-05
I would like to make a dbGrid cell look like an excel cell that has a memo attached. That is it has a small red triangle at the top right of the cell, holding the mouse over the red triangel causes a floating dialogue box to appear with the memo.

Help would be appreciated
0
Comment
Question by:alanjbrown
  • 6
  • 4
10 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9737175
Try something like this:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  Grid: TDBGrid;
begin
  Grid := Sender as TDBGrid; // so we don't have to cast the darn thing
  case DataCol of
  0: // Your memo field column number...
    begin
      Grid.Canvas.Brush.Color := clRed;
      Grid.Canvas.Rectangle(Rect.Right-5, rect.Top, Rect.Right, Rect.Top+5);
    end; {case:0}
  end; {case}
  Grid.DefaultDrawing := True;
end;

0
 
LVL 1

Author Comment

by:alanjbrown
ID: 9738961
Thanks EddieShipman.

That is a useful start. Is it possible to display a triangle instead of a rectangle?

I also need to be able to detect when the mouse is over the area so that I can display a panel with the text in it next to the cell.

 
0
 
LVL 1

Author Comment

by:alanjbrown
ID: 9739029
I have managed the triange part by using grid.canvas,polygon instead of rectangle.

0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9739721
Oh, I thought you said rectangle., sorry...

You have in the TDBGrid.MouseCoords function that you can use in the mouse move
Heres an example from the Borland newsgroups by Frank Plevniak
(found using search at http://www.tamaracka.com)

type
  TMyGrid = class(TDBGrid)
  public
    {Redeclare the DataLink property as public so we can use it}
    property DataLink;
  end;

{...implementation of TForm1...}

procedure TForm1.MouseMove(Sender: TObject; Shift: TShiftState; X, Y:
Integer);
var
  OldActive: Integer
  MyGrid :TMyGrid;
begin
  if not (Sender is TDBGrid)
  then raise Exception.Create('Need TDBGrid to do this!');
  MyGrid := TMyGrid(Sender);
  Coord := MyGrid.MouseCoord(X, Y);
  if (Coord.Y < 0)
  then Exit; {The column header triggers a mouse move event too, must ignore}
  {Now we can look for our hint text}
  OldActive := MyGrid.DataLink.ActiveRecord;
  try
    {This method locates the field the mouse is hovering over using the "relative" grid coordinates}
    MyGrid.DataLink.ActiveRecord := Coord.Y - 1; {Dec() here because the first row is 1 but we need 0 based access}
    {The field value is now available for use, access it to assign the hint!}
    MyGrid.Hint := MyGrid.Fields[0{Hint Text Field}].AsString;
  finally
    dbGrid.DataLink.ActiveRecord := OldActive;
  end;
  {More code goes here to force the display of the new Hint text}
end;
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9739730
However, this would get the coords of the enitre CELL. Let me think about this one for a moment.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 26

Expert Comment

by:EddieShipman
ID: 9749960
Can you show me how you are creating the polygon and then drawing the triangle?
0
 
LVL 1

Author Comment

by:alanjbrown
ID: 9758151
For rectangle :-
 Grid.canvas.Rectangle(rect.right -5, rect.top, rect.right, rect.top +5);

For Triangle :-
Grid.canvas.Polygon([point(rect.right -7, rect.top), point(rect.right, rect.top),point(rect.right, rect.top +7)]);
   
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 500 total points
ID: 9763638
What you want to do is something like this:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  LGrid: TDBGrid;
  LPoints: array[0..2] of TPoint;
  i: Integer;
begin
  LGrid := Sender as TDBGrid; // so we don't have to cast the darn thing
  case DataCol of
  0: // Your memo field column number...
    begin
      LGrid.Canvas.Brush.Color := clRed;
      // Make the region two pixels bigger than the triangle
      LPoints[0] := Point(Rect.Right - 9, Rect.Top);
      LPoints[1] := Point(Rect.Right, Rect.Top);
      LPoints[2] := Point(Rect.Right, Rect.Top + 9);
      Rgn := CreatePolygonRgn(LPoints,3,WINDING);
      LGrid.Canvas.Polygon(LPoints);
    end; {case:0}
  end; {case}
  LGrid.DefaultDrawing := True;
end;

procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if PtInRegion(Rgn, x, y) then
  begin
    ShowMessage('there');
  end;
end;


Of course this will only operate on the lst drawn cell with the triangle so you will need to
devise a way to create a rgn for each cell and store it in some list and then check the
entire list in the mosemove to see if the pt is in any of the regions in the list.
0
 
LVL 1

Author Comment

by:alanjbrown
ID: 9766573
EddieShipman

I am still having difficulty with the mouse move event. I can pick up the mouse move when it is outside the dbgrid but not when it is on the grid.

I have increased the points for this question because, initially I did not realise just how difficult it would be.




0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9766923
I was able to catch the mousemove on the LAST row. Because it si the last one drawn, it has
the RGN. I suggested to create an array or list of HRGNs, one for each visible row, and then
check each of them in the mousemove to see if the pt is in any HRGN for any of them. Then
do whatever you want when you are on the one.

I will work a little more to see if I can come up with something.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

11 Experts available now in Live!

Get 1:1 Help Now