Forum > LCL

[SOLVED] How to Highlight a Treeview node on DragOver event

(1/1)

jamestien:
Hello mate,

Any hint on to highlight the node to reflect it as drop target during Treeview.OnDragOver event? I've searched the forum topics but found none.

howardpc:
It is not clear what you want to drop on your treeview's node. But for the simple case of dragging another node from the treeview itself, the attached (incomplete) project shows one way to go about this.
It is incomplete because no action is taken when the node is dropped, and because the Accept parameter is simply set to True unless you try to drop a node on itself. A real app would obviously have a customised algorithm for this so only acceptable nodes were highlighted.


jamestien:

--- Quote from: howardpc on October 24, 2021, 05:56:49 pm ---It is not clear what you want to drop on your treeview's node. But for the simple case of dragging another node from the treeview itself, the attached (incomplete) project shows one way to go about this.
It is incomplete because no action is taken when the node is dropped, and because the Accept parameter is simply set to True unless you try to drop a node on itself. A real app would obviously have a customised algorithm for this so only acceptable nodes were highlighted.

--- End quote ---

Thank you howardpc.
Tested your example, its just what I was looking for. btw, Im drag & drop items from Listview to Treeview, with your sample, I think I can manage to make it work.

jamestien:
One more question, how can we stop showing the Gray target rect as seen in the screenshot?

jamestien:
Got it.
To remove that Gray rect, I need to set a Flag to indicate that item has been dropped and not to draw it as drop target (highlight).

1. set ItemDropped = FALSE in DragOver event.
2. set ItemDropped = TRUE after process DragDrop event.



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.TV1AdvancedCustomDrawItem(Sender: TCustomTreeView;  Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;  var PaintImages, DefaultDraw: Boolean);var  textR: TRect;  textY: Integer;begin  if Stage = cdPostPaint then      Exit;  case node.Equals(HighlightNode) and (not ItemDropped) of    FALSE:      begin         DefaultDraw := True;         Exit;      end;    TRUE:      DefaultDraw := False;  end;   {draw highlight item here} end; 

Navigation

[0] Message Index

Go to full version