K
kaithink
Unregistered / Unconfirmed
GUEST, unregistred user!
请教:<br>如何可在DBGRID或其它GRID里,当鼠标移动到哪个单元格上时HINT显示或在别处的EDIT里显示鼠标指针下的单元格内容。注意:该单元格并未获得焦点<br><br>同类的问题:如何可做到让DBGRID的单元格焦点随鼠标指针的移动而移动,也就是光标跟随鼠标移动。<br>
unit DBGrid1;<br><br>interface<br><br>uses<br> SysUtils, Classes, Controls, Grids, DBGrids;<br><br>type<br> TDBGrid1 = class(TDBGrid)<br> private<br> { Private declarations }<br> protected<br> { Protected declarations }<br> procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; <br> public<br> { Public declarations }<br> published<br> { Published declarations }<br> end;<br><br>procedure Register;<br><br>implementation<br><br>procedure Register;<br>begin<br> RegisterComponents('Samples', [TDBGrid1]);<br>end;<br><br>{ TDBGrid1 }<br><br>procedure TDBGrid1.MouseMove(Shift: TShiftState; X, Y: Integer);<br>var<br> CellHit: TGridCoord;<br>begin<br> inherited MouseMove(Shift,X,Y);<br> if FGridState=gsNormal then<br> begin<br> CellHit := MouseCoord(X, Y);<br> if (CellHit.X >= FixedCols) and (CellHit.Y >= FixedRows) then<br> begin<br> if dgEditing in Options then<br> begin<br> if (CellHit.X = Col) and (CellHit.Y = Row) then<br> ShowEditor<br> else<br> begin<br> Col := CellHit.X;<br> Row := CellHit.Y;<br> ShowEditor;<br> end;<br> Click;<br> end<br> else<br> begin<br> Col := CellHit.X;<br> Row := CellHit.Y;<br> end;<br> end<br> end;<br>end;<br><br>end.
procedure TDBGrid1.MouseMove(Shift: TShiftState; X, Y: Integer);<br>var<br> CellHit: TGridCoord;<br>begin<br> inherited MouseMove(Shift,X,Y);<br> if FGridState=gsNormal then<br> begin<br> CellHit := MouseCoord(X, Y);<br> if DataLink.Active then<br> begin<br> if (CellHit.X >= FixedCols) and (CellHit.Y >= FixedRows) then<br> begin<br> if dgEditing in Options then<br> begin<br> if (CellHit.X = Col) and (CellHit.Y = Row) then<br> ShowEditor<br> else<br> begin<br> Col := CellHit.X;<br> Datalink.DataSet.MoveBy(CellHit.Y - Row);<br> Row := CellHit.Y;<br> HighlightCell(Col,Row,'',[]);<br> end;<br> Click;<br> end<br> else<br> begin<br> Col := CellHit.X;<br> Datalink.DataSet.MoveBy(CellHit.Y - Row);<br> Row := CellHit.Y;<br> end;<br> end;<br> end;<br> end;<br>end;