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

x
?
Solved

Excel style memo indicator in dbGrid

Posted on 2003-11-12
10
Medium Priority
?
591 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Independent Software Vendors: 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!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
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

783 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