Solved

Excel style memo indicator in dbGrid

Posted on 2003-11-12
10
579 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
[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
  • 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
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 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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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 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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

690 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