Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.