Tuesday, June 9, 2009

How to Get DBGrid Cell Coordinates on StatusBar


Source code from delphi.about.com for get DBGrid Cell Coordinate on statusbar was modified by newbiedelphiphp, look below source.

The code to show over what cell in a DBGrid the cursor is, and how to change the cursor on status bar:

procedure Tfrandom.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var   pt: TGridcoord;
begin
  pt:= DBGrid1.MouseCoord( x, y ) ;
  //change the cursor whe over title
  if pt.y=0 then
    DBGrid1.Cursor:=crHandPoint
  else
    DBGrid1.Cursor:=crDefault;
   If pt.X > 0 Then
     begin
     Caption := Format( 'Kolom: %d, Baris: %d, title: %s',
                [pt.x, pt.y, DBGrid1.columns[pt.x-1].title.caption] );
     statusbar.Panels[1].Text:=Caption;
     end
   Else
     Caption := Format( 'Kolom: %d, Baris: %d',[pt.x, pt.y] ) ;
end;


I was used Borland Delphi 7, if you use delphi 6 i think it’s no different.



Enjoy it!!!

0 Responses to “How to Get DBGrid Cell Coordinates on StatusBar”