TreeView & Scrollbar - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

TreeView & Scrollbar

Hi all;
For example i do this:

TreeView1.Selected := OneOfTheNodesOnTheTree;

After making it selected, if this node is not in the visible area,
how can i make the tree view scroll to the appropriate area where the selected node can be viewed easily?

As a second question, when i drag a node in the tree view upwards, i want the scrollbar to be automatically scrolled upwards when the dragged node reaches to the upper boundary of the tree view. Is it possible?

Thanx in advance...

Comments

  • injektiloinjektilo Posts: 113Member
    : Hi all;
    : For example i do this:
    :
    : TreeView1.Selected := OneOfTheNodesOnTheTree;
    :
    : After making it selected, if this node is not in the visible area,
    : how can i make the tree view scroll to the appropriate area where the selected node can be viewed easily?

    >>>>>>>>>>>>>>>
    setting HideSelection to False should do it.


    : As a second question, when i drag a node in the tree view upwards, i want the scrollbar to be automatically scrolled upwards when the dragged node reaches to the upper boundary of the tree view. Is it possible?
    :
    : Thanx in advance...
    :

    [code]
    procedure TForm1.MoveNode(TargetNode, SourceNode: TTreeNode);
    var
    nodeTmp : TTreeNode;
    i : Integer;
    begin
    with TreeView1 do
    begin
    nodeTmp := Items.AddChild(TargetNode,SourceNode.Text);
    for i := 0 to SourceNode.Count -1 do
    begin
    MoveNode(nodeTmp,SourceNode.Item[i]);
    end;
    end;
    end;


    procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
    var
    TargetNode, SourceNode : TTreeNode;
    begin
    with TreeView1 do
    begin
    TargetNode := GetNodeAt(X,Y); // Get target node
    SourceNode := Selected;
    if (TargetNode = nil) then
    begin
    EndDrag(False);
    Exit;
    end;
    MoveNode(TargetNode,SourceNode);
    SourceNode.Free;
    end;
    end;

    procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
    State: TDragState; var Accept: Boolean);
    begin
    if (Sender = TreeView1) then // If TRUE than accept the draged item
    begin
    Accept := True;
    if (y < 15) then
    SendMessage(TreeView1.Handle, WM_VSCROLL, SB_LINEUP, 0)
    else if (TreeView1.Height - y < 15) then
    SendMessage(TreeView1.Handle, WM_VSCROLL, SB_LINEDOWN, 0);
    end;
    end;
    [/code]
Sign In or Register to comment.