2

I'm dragging a node from one app to another. It's working fine only if I previously select node. It's because I collect data using GetNodeData(FocusedNode) method.

I'd like somehow auto-focus the node on node hover. Is it possible?

I'm using VirtualTreeView v. 4.8.7

TLama
  • 75,147
  • 17
  • 214
  • 392
Jacek Kwiecień
  • 12,397
  • 20
  • 85
  • 157
  • Got toSimpleDrawSelection set to False and toFullRowSelect set to False – Jacek Kwiecień Mar 07 '12 at 14:43
  • The title talks about *selecting*, but the body talks about *focusing*. Those are independent states, so which do you really want? Can you please be more specific about what fails? – Rob Kennedy Mar 07 '12 at 14:46
  • @ Rob Kennedy: To start drag I have to select (focus) node first, so I could use FocusedNode property. @TLama both are set to False – Jacek Kwiecień Mar 07 '12 at 14:51
  • 1
    @Rob, one thing is IMHO sure; you cannot drag if you don't have some node focused (thus some node selected). And therefore there's a check `IsAnyHit` before the tree starts to `BeginDrag`. – TLama Mar 07 '12 at 14:52
  • 1
    I'm still not clear on what's failing. How does dragging start? (manual, or automatic?) When dragging starts, are you saying there is no focused node? I don't see how that can be, since `HandleMouseDown` calls `DoFocusChange` just before calling `BeginDrag`. Where are you calling `GetNodeData(FocusedNode)`? – Rob Kennedy Mar 07 '12 at 15:20
  • I want to drag without focusing node first. It seems the node is selected OnMouseUp - when u drag its only MouseDown - if you havent selected the node first, u can't drag it. Seriously its not that hard to imagine – Jacek Kwiecień Mar 07 '12 at 21:20
  • Perhaps a node *is* selected on mouse up, but who cares about selection? A node is *focused* on mouse down. You can see that happen in `HandleMouseDown`, can't you? Again I ask, *how does dragging start?* Does dragging start as soon as the mouse button is pressed, or do you have to move the mouse a little bit first? Do you call `BeginDrag`, or does the tree call it for you? – Rob Kennedy Mar 07 '12 at 21:25
  • I have an impression that draging is start a moment after mouse is pressed. The I get an exception because data := drzewo.GetNodeData(drzewo.FocusedNode); was nil – Jacek Kwiecień Mar 08 '12 at 07:13
  • Wait, wait, wait. Drag is being started (in short) when you press and hold the mouse button when you have some node(s) selected, that's the moment when the `BeginDrag` is called. Sorry, I really have no idea what you are expecting or what you want to achieve because if you want to drag you have to press the button (except that you would have some device reading your mind and deciding that you want to drag). – TLama Mar 08 '12 at 08:47
  • Well, My friend doing same project in .NET maneged to focus node using mouse pointer position but he has some special method of treelist avalible. i was just trying to acomplish something similiar. i guess delphi is not that powerful – Jacek Kwiecień Mar 08 '12 at 09:01
  • 1
    It's not about Delphi, but about the TreeView itself and it is very powerful. I seriously have no clue what you want to do. So you want to focus node when you hover it ? If so, take a look at my answer. – TLama Mar 08 '12 at 09:23

1 Answers1

5

If you want to focus and select node when you hover it, try the OnHotChange event with the following

procedure TForm1.VirtualStringTree1HotChange(Sender: TBaseVirtualTree; OldNode,
  NewNode: PVirtualNode);
begin
  VirtualStringTree1.FocusedNode := NewNode;
  VirtualStringTree1.Selected[NewNode] := True;
end;
TLama
  • 75,147
  • 17
  • 214
  • 392
  • 1
    omg, omg, thats TOTALLY what I've been looking for. It also makes navigating over the tree easier thanks to autofocusing on hover. Thank you mate, I owe you! – Jacek Kwiecień Mar 09 '12 at 08:52
  • You're welcome. I've modified the question, because it was not about dragging, but about node selection on hover. – TLama Mar 09 '12 at 09:03