Solved

Scroll in TreeView components

Posted on 2003-10-30
4
474 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now