Q&A

  • DBGrid에서 특정 Field hint 보기
안녕하세요..
궁금한 사항이 있어 글을 올립니다.
DBGrid에서 특정 Feild에 마우스를 대면 hint가 나오게 할수 있나요?

전체 그리드가 아닌 특정 필드요..

음.. 좋은 조언 부탁드립니다.
1  COMMENTS
  • Profile
    구창민 2003.02.18 05:11
    안녕하세요~ 구창민입니다.

    참고하시고 즐거운 프로그래밍 하시길~~


    unit DBGridEx;
    { ==================================================== }

    { ==================================================== }
    interface
    { ==================================================== }
    uses DBGrids, Grids, Controls, Classes, Forms;

    type
        TDBGridEx = class( TDBGrid )

          private
            OldGridCoord : TGridCoord;
          public
            Application : TApplication;

            function MouseCoord(X, Y: Integer): TGridCoord;
            function GetEditText(ACol, ARow: Longint): string;override;
            procedure MouseMove(Shift: TShiftState; X, Y: Integer);override;



          published


            property OnMouseMove;
            property OnMouseDown;
            property OnMouseUp;

        end;

    procedure Register;

    { ==================================================== }
    implementation
    { ==================================================== }

    function TDBGridEx.MouseCoord(X, Y: Integer): TGridCoord;
    begin
      Result := inherited MouseCoord(X, Y);
    end;

    function TDBGridEx.GetEditText(ACol, ARow: Longint): string;
    begin
      if (ACol > 0) and (ACol < ColCount) and (ARow > 0) and (ARow < RowCount)
    then
        Result := inherited GetEditText(ACol, ARow)
      else
        Result := '';
    end;

    procedure TDBGridEx.MouseMove(Shift: TShiftState; X, Y: Integer);
    Var
    C:TGridCoord;
    OldActive:Integer;
    Value:String;
    begin
      inherited MouseMove (Shift, X, Y);

       C:=MouseCoord(X,Y);
       if (OldGridCoord.X = C.X) and (OldGridCoord.Y = C.Y) then Exit;

       OldGridCoord := C;

       Value := '';
       OldActive := DataLink.ActiveRecord;
       Try
        if C.Y > 0 then
          DataLink.ActiveRecord := C.Y-1
        else
          DataLink.ActiveRecord := C.Y;
        {Value := GetFieldValue(C.X);}

        Value := GetEditText(C.X,C.Y);


       Finally
        DataLink.ActiveRecord := OldActive;
       End;

       if Application <> nil then
         Application.CancelHint;

       Hint:=Value;

    end;

    { ==================================================== }

    procedure Register;
    begin
      RegisterComponents('Data Controls',[TDBGridEx]);
    end;

    { ==================================================== }
    end.