Правим компоненты TMS Component Pack 6.5.0.0.
делаем нормальное дерево для решетки TAdvStringGrid
результат: узлы дочерние будут привязаны к узлам родительским, а не висеть в воздухе, не будет лишних вертикальных линий
procedure DrawCellGraphic(r: TRect; CellGraphic: TCellGraphic; VertAlign: TVAlignment);
procedure TAdvStringGrid.DrawGridCell(Canvas: TCanvas; ACol, ARow : longint; ARect : TRect;
AState : TGridDrawState);
делаем нормальное дерево для решетки TAdvStringGrid
результат: узлы дочерние будут привязаны к узлам родительским, а не висеть в воздухе, не будет лишних вертикальных линий
Код:
function TAdvStringGrid.GetNodeSpanType(ARow: Integer): Integer;
var
i: Integer;
begin
Result := 0;
if IsNode(ARow) then
begin
Exit;
end;
if ARow >= RowCount - FixedFooters - 1 then
begin
Result := 1;
Exit;
end;
if HasCellProperties(0,ARow + 1) then
begin
if (CellProperties[0,ARow + 1].NodeLevel >= CellProperties[0,ARow].NodeLevel) then
begin
if (CellTypes[0,ARow + 1] = ctNode) then Result := 1
else Result := 2;
end
else
Result := 1;
end
else
begin
Result := 1;
end;
Exit;
...
procedure DrawCellGraphic(r: TRect; CellGraphic: TCellGraphic; VertAlign: TVAlignment);
Код:
...
ctNode:
begin
r.Left := NodeIndent(ARow) - CellNode.NodeIndent;
if FCellNode.ShowTree and (ARow >= FixedRows) {and not CellGraphic.CellBoolean} then
begin
Canvas.Pen.Color := FCellNode.TreeColor;
Canvas.Pen.Width := 1;
// if (ACol < FixedCols) and not Flat and (Flook in [glTMS,glXP,glListView,glSoft]) then
// r.Left := r.Left - 1;
if (NodeIndent(ARow + 1) > 0) and (ARow + 1 < RowCount) and not (NodeState[ARow] and (NodeIndent(ARow + 1) < NodeIndent(ARow)) ) then
begin
PrevIndent:=r.Left + 2 - CellNode.NodeIndent div 2;
if(PrevIndent<2) then PrevIndent:=2;
Canvas.MoveTo(PrevIndent,r.Top + (r.Bottom - r.Top) div 2);
Canvas.LineTo(r.Left + 2 + CellNode.NodeIndent div 2,r.Top + (r.Bottom - r.Top) div 2);
Canvas.LineTo(r.Left + 2 + CellNode.NodeIndent div 2,r.Bottom);
end;
{if (NodeIndent(ARow - 1) >= NodeIndent(ARow)) then
begin
Canvas.MoveTo(r.Left + 2 + CellNode.NodeIndent div 2,r.Top);
Canvas.LineTo(r.Left + 2 + CellNode.NodeIndent div 2,r.Top + 6);
end;}
if (ACol < FixedCols) and not Flat and (Flook in [glTMS,glXP,glListView,glSoft]) then
r.Left := r.Left + 1;
end;
...
procedure TAdvStringGrid.DrawGridCell(Canvas: TCanvas; ACol, ARow : longint; ARect : TRect;
AState : TGridDrawState);
Код:
...
NodeRow,NodeLevel,CurrentLevel: integer;
...
if (FNumNodes > 0) and (ACol = 0) and (ARow >= FixedRows) and (FCellNode.ShowTree) then
begin
Canvas.Pen.Color := FCellNode.TreeColor;
Canvas.Pen.Width := 1;
lvl := CellProperties[0,ARow].NodeLevel;
ARect.Left := NodeIndent(ARow);
ci := ARect.Left - CellNode.NodeIndent + 2 + CellNode.NodeIndent div 2;
if (lvl > 0) then
begin
// horizontal node line
Canvas.MoveTo(ci,ARect.Top + (ARect.Bottom - ARect.Top) shr 1);
if FCellNode.ShowTreeFull then
Canvas.LineTo(ARect.Right,ARect.Top + (ARect.Bottom - ARect.Top) shr 1)
else
Canvas.LineTo(ARect.Left + 4,ARect.Top + (ARect.Bottom - ARect.Top) shr 1);
end;
case GetNodeSpanType(ARow) of
1:begin
Canvas.MoveTo(ci,ARect.Top);
Canvas.LineTo(ci,ARect.Top + (ARect.Bottom - ARect.Top) shr 1);
end;
2:begin
Canvas.MoveTo(ci, ARect.Top );
Canvas.LineTo(ci, ARect.Bottom + 4);
end;
end;
if HasCellProperties(0,ARow) then
begin
CurrentLevel := CellProperties[0,ARow].NodeLevel;
NodeRow := ARow;
while (CurrentLevel>1) do
begin
NodeLevel := CurrentLevel + 1;
while (NodeLevel>CurrentLevel) do
begin
NodeRow := NodeRow + 1;
if (NodeRow=RowCount) then NodeLevel := 0
else
if (CellTypes[ACol,NodeRow]=ctNode) then NodeLevel := CellProperties[0,NodeRow].NodeLevel;
end;
while (NodeLevel<CurrentLevel) do
begin
CurrentLevel := CurrentLevel - 1;
if (CurrentLevel = (CellProperties[0,ARow].NodeLevel - 1)) then
if (CellTypes[ACol,ARow] = ctNode) then
begin
Canvas.MoveTo(ci - CellNode.NodeIndent * (CellProperties[0,ARow].NodeLevel - CurrentLevel), ARect.Top );
Canvas.LineTo(ci - CellNode.NodeIndent * (CellProperties[0,ARow].NodeLevel - CurrentLevel), ARect.Top + (ARect.Bottom - ARect.Top) shr 1);
Canvas.LineTo(ci - CellNode.NodeIndent * (CellProperties[0,ARow].NodeLevel - CurrentLevel) + CellNode.NodeIndent, ARect.Top + (ARect.Bottom - ARect.Top) shr 1);
end;
end;
if(CurrentLevel>1) then
CurrentLevel := CurrentLevel - 1;
begin
Canvas.MoveTo(ci - CellNode.NodeIndent * (CellProperties[0,ARow].NodeLevel - CurrentLevel), ARect.Top );
Canvas.LineTo(ci - CellNode.NodeIndent * (CellProperties[0,ARow].NodeLevel - CurrentLevel), ARect.Bottom + 4);
end;
end;
{// draw straight interconnecting lines
for vpos := 1 to CellProperties[0,ARow].NodeLevel do
begin
// draw line till middle of cell
Canvas.MoveTo(ci - CellNode.NodeIndent * vpos, ARect.Top );
Canvas.LineTo(ci - CellNode.NodeIndent * vpos, ARect.Top + (ARect.Bottom - ARect.Top) shr 1);
if (ARow < RowCount - 1) then
begin
if (CellProperties[0,ARow + 1].NodeLevel = 0) then
begin
if (vpos < CellProperties[0,ARow].NodeLevel) then
Canvas.LineTo(ci - CellNode.NodeIndent * vpos + CellNode.NodeIndent, ARect.Top + (ARect.Bottom - ARect.Top) shr 1)
end
else
// draw till bottom
Canvas.LineTo(ci - CellNode.NodeIndent * vpos, ARect.Bottom + 4);
end
else
begin
if (vpos < CellProperties[0,ARow].NodeLevel) then
Canvas.LineTo(ci - CellNode.NodeIndent * vpos + CellNode.NodeIndent, ARect.Top + (ARect.Bottom - ARect.Top) shr 1);
//Canvas.LineTo(ci - CellNode.NodeIndent * vpos, ARect.Bottom + 4);
end;
end;}
end;
Canvas.Pen.Style := psSolid;
end;
...