Delphi – expand/collapse TreeView only by node image click

delphi

I have on my form a TreeView with a lots of items/nodes. When I double click a item of a node I run a procedure (depending of the clicked item).My problem is that I want it to expand/collapse only when I click on the icon of the node ( the + or – sign), not if I double click an item

similar question

Best Answer

You may use the AllowCollapse and AllowExpand parameters of the OnCollapsing and OnExpanding events, to prevent the node from being collapsed or expanded.

Combine that with the appropiate logic to recognize the part of the node being clicked on. If the generating click was on the icon, let the action progress, if not, then ignore it (setting AllowXxxxx:=false)

But be careful not to break keyboard navigation. So you will need to check the origin of the event, and in case of a keyboard event (cursor left/right) leave the action progress.

To keep track of the originator event, capture the OnMouseDown and OnKeyDown events, and set an internal indicator of the type of the latest one received, so you may check for the later OnCollapsing and OnExpanding event process.

Related Topic