2010-08-05 2 views

답변

2

Tofig, 현재 행 안부를 얻기 위해 MouseCoord 절차를 사용할 수 있습니다,하지만 당신은 행 값으로 DataLink.ActiveRecord 속성을 설정하고 보호 속성에 액세스 할 수있는 새로운 클래스 하위를 작성해야합니다 [Col,Row]는 POS의 값을 보여 .

체크 당신은 MouseCoord을받을 필요가 없습니다 코드

type 
THackGrid = class(TCustomDBGrid); //Create a new class to access the protected properties 


procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, 
    Y: Integer); 
var 
    Cell    : TGridCoord; 
    Row,Col   : integer; 
    OrigActiveRecord : integer; 
begin 
    inherited; 
    Cell:=DBGrid1.MouseCoord(X,Y); 
    Col:= Cell.X; 
    Row:= Cell.Y; 

    if dgTitles in DBGrid1.Options then Dec(Row); //if the titles are shown then adjust Row index (-1); 
    if dgIndicator in DBGrid1.Options then Dec(Col); //if the indicator is shown then adjust the Column index (-1); 

    if THackGrid(DBGrid1).DataLink.Active and (Row>=0) and (Col>=0) then 
    begin 
     OrigActiveRecord:=THackGrid(DBGrid1).DataLink.ActiveRecord; //save the original index 
     try 
     THackGrid(DBGrid1).DataLink.ActiveRecord:= Row; 
     Label1.Caption:=DBGrid1.Columns[Col].Field.AsString; //show the current value in a tlabel 
     finally 
     THackGrid(DBGrid1).DataLink.ActiveRecord:= OrigActiveRecord; //restore the index 
     end; 
    end; 
end; 
+0

. OnMouseMove 이벤트에 이미 이벤트가 있습니다. – Linas

+0

@Linas에서 X와 Y 값은 점 (X, Y)를 반환합니다.이 값을 col와 row 인덱스로 변환하려면 MouseCoord 함수가 필요합니다. http://docwiki.embarcadero.com/VCL /en/Grids.TCustomGrid.MouseCoord – RRUZ

+0

감사합니다. 나는 더 쉬운 방법이 있어야한다는 느낌이 들었다. 나는 DbGrid가이 값들을 어딘가에 저장해야한다는 것을 의미합니다. 우리는 어떻게해서든지 그들을 직접 접근 할 수는 없습니까? –

관련 문제