It would be better if this were incorporated into the ElPack code.
procedure ScrollColumn(const XTree : TElXTree; const n : Integer);
var
Indexes : TArray<Integer>;
Widths : TArray<Integer>;
LeftPositions : TArray<Integer>;
LeftColumn : Integer;
procedure DetermineWidthsInOrder();
var
i : Integer;
begin
SetLength(Widths, Length(Indexes));
with XTree.HeaderSections do
begin
for i := 0 to High(Widths) do
begin
Widths[i] := Sections[Indexes[i]].Width;
end;
end;
end;
procedure DetermineLeftPositions(); // NB: Assumes 1 Fixed Column!
var
i : Integer;
begin
SetLength(LeftPositions, Length(Indexes));
LeftPositions[1] := 0;
for i := 2 to High(LeftPositions) do
begin
LeftPositions[i] := LeftPositions[i - 1] + Widths[i - 1];
end;
end;
function CalcLeftScrollableColumn() : Integer; // NB: Assumes 1 Fixed Column!
var
i : Integer;
begin
Result := 1;
for i := 2 to High(LeftPositions) do
begin
with XTree do
begin
if (LeftPosition >= LeftPositions[i] - 10)
and (LeftPosition <= LeftPositions[i] + Widths[i] - 1 - 10) then
begin
Result := i;
Exit;
end;
end;
end;
end;
begin
DetermineVisibleFieldOrder(XTree, Indexes);
DetermineWidthsInOrder();
DetermineLeftPositions(); // NB: Assumes 1 Fixed Column!
LeftColumn := CalcLeftScrollableColumn();
with XTree do
begin
if n < 0 then
begin
if LeftColumn > 1 then
begin
LeftPosition := LeftPositions[LeftColumn - 1]
end
else
begin
LeftPosition := LeftPositions[1]
end;
end
else // n > 0
begin
if LeftColumn < High(LeftPositions) then
begin
LeftPosition := LeftPositions[LeftColumn + 1]
end;
end;
end;
end;
Comments
2.) GetLeftVisibleColumn() / procedure SetLeftVisibleColumn(const Column : Integer)
1. is rather specific, but setting the left first visible column (like TopIndex) might be a sensible addition. I added suggestion to feature requests.