Solved

Scroll in TreeView components

Posted on 2003-10-30
4
478 Views
Last Modified: 2010-04-05
I have a TreeView (in a Delphi 7 program) and one of the operations I want supported is to "Move" elements between nodes. The problem is that when I'm dragging an element and the target node is out of sight the view does not scroll down to show the other elements.

How can I add scroll up and down when the cursor gets out of the control's boundaries ?

Thanks in advance !


AJ
0
Comment
Question by:ajgonzalezm
4 Comments
 
LVL 5

Accepted Solution

by:
snehanshu earned 50 total points
ID: 9654776
Does this help?
(Changing Drag-Over event of the TreeView);

procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
   // draggin over
  if (Sender is TForm) and (Source is TTreeView) then
    begin
    with Source as TTreeView do
        // check if we are in the hot zone (in this case only above or below)
      if (x > Left) and (x < Left + Width) and
         (y > Top - HOTZONE_WIDTH) and (y < Top + Height + HOTZONE_WIDTH)
        then begin
          Accept := true;  // we could set false here, too.
          if y < Top
            then Perform(WM_VSCROLL, SB_LINEUP, 0)
            else Perform(WM_VSCROLL, SB_LINEDOWN, 0);
          end
        else Accept := false;
    end
  else
    Accept := (Sender = Source);
end;

I picked this up from
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10125137.html?query=TreeView+Scroll&searchType=topic

HTH,
...Snehanshu
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 50 total points
ID: 9677227
well, another method

procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
var ANode : TTreeNode;
begin
  ANode := TreeView1.GetNodeAt(x,y);
  Accept := assigned(ANode); //just as sample
  //Scrolling needed ?
  if ((y < 9) or
     (y > TreeView1.Height - 9)) and
     (assigned(ANode)) then
    //ScrollUp ?
    if (y < 5) then
      ANode := ANode.getPrevSibling
    else
      ANode := ANode.getNextSibling;
  If assigned(ANode) then
    ANode.MakeVisible;
end;

meikl ;-)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question