1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| Type
TForm1 = class(TForm)
ScrollBox1: TScrollBox;
grTitles, grDatas : tstringgrid;
(...)
Private
Fbool : boolean ;
FPosition : integer;
(...)
procedure TForm1.grDatasMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Begin
if Fbool then
scrollbox1.HorzScrollBar.Position := FPosition ;
Fbool := false ;
End;
procedure TForm1.ajusteGrilles(grFixe, grMobile : TStringGrid) ;
// ajuste horizontalement les 2 stringgrid
var
i,j : integer ;
Begin
j:= 0 ;
for i:=0 to (grFixe.colCount-1) do begin
grMobile.colWidths[i] := grFixe.colWidths[i] ;
j:= j+ grFixe.colWidths[i] ;
end;
scrollbox1.HorzScrollBar.Range := j+ 20 ;
End;
procedure TForm1.grTitlesMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
aCol, aRow : longInt ;
iLargeurMin : integer ;
Begin
if Fbool then
scrollbox1.HorzScrollBar.Position := FPosition ;
Fbool := false ;
grTitles.MouseToCell(X, Y, aCol, aRow) ;
if (Button=mbRight)and(aRow=0) then begin
iLargeurMin := round(grTitles.canvas.textWidth(monTrim(grTitles.Columns[aCol].title.caption))+20) ;
grDatas.ajusteTailleColonnes(aCol, iLargeurMin) ;
ajusteGrilles(grDatas, grTitles) ;
end;
End;
procedure TForm1.grTitlesExit(Sender: TObject);
begin
Fbool := true ;
FPosition := scrollbox1.HorzScrollBar.Position ;
end;
procedure TForm1.grDatasExit(Sender: TObject);
begin
Fbool := true ;
FPosition := scrollbox1.HorzScrollBar.Position ;
end;
procedure TForm1.grDatasSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
// fait bouger la scrollbox pour rendre la cellule sélectionnée visible
Begin
if not Fbool then begin
while (grDatas.cellRect(aCol, aRow).left<abs(grDatas.left))
and(scrollbox1.HorzScrollBar.Position>0) do begin
scrollbox1.HorzScrollBar.Position := scrollbox1.HorzScrollBar.Position-10 ;
self.repaint() ;
end ;
while (grDatas.cellRect(aCol, aRow).right>abs(grDatas.left)+scrollbox1.clientWidth)
and(scrollbox1.HorzScrollBar.Position<scrollbox1.HorzScrollBar.range-scrollbox1.clientWidth) do begin
scrollbox1.HorzScrollBar.Position := scrollbox1.HorzScrollBar.Position+10 ;
self.repaint() ;
end ;
FPosition := scrollbox1.HorzScrollBar.Position ;
end ;
End; |
Partager