Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 486
  • Last Modified:

Scroll in TreeView components

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
ajgonzalezm
Asked:
ajgonzalezm
2 Solutions
 
snehanshuCommented:
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
 
kretzschmarCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now