Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-09

VirtualTreeView: Expand/Collapse without OnNodeClick

8 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jürgen Hestermann

I already spend quite a lot of time to find a way around a certain behaviour in VirtualTreeView (5.5.3-R1) but with no luck:

When I click on a plus/minus button left of a node in the tree to collapse/expand all sub-nodes then always the event OnNodeClick is called too.

It seems to be impossible to start an action by clicking on a node while still allowing to collapse/expand sub-nodes as a stand-alone function.
It's annoying to have the event fired when I only want to expand/collapse nodes.

Is this (again) a bug in VTV or is there a way to
avoid this behaviour?

Reply by email

Balázs Székely
to Jürgen Hestermann

This should work:

procedure TfMain.VSTCollapsing(Sender: TBaseVirtualTree; Node: PVirtualNode;
  var Allowed: Boolean);
begin
  CollapsingOrExapnding := True;
end;
procedure TfMain.VSTExpanding(Sender: TBaseVirtualTree; Node: PVirtualNode;
  var Allowed: Boolean);
begin
  CollapsingOrExapnding := True;
end;
procedure TfMain.OnNodeClick(Sender: TObject);
begin
  if not CollapsingOrExapnding then
  begin
    //regular node click(not +/- buttons), do something...
    ShowMessage('ok')
  end
  else
    CollapsingOrExapnding := False;
end;

Reply by email

Jürgen Hestermann
to Balázs Székely
Balázs Székely wrote 21 lines
This should work: procedure TfMain.VSTCollapsing(Sender: TBaseVirtualTree; Node: PVirtualNode; var Allowed: Boolean); begin CollapsingOrExapnding := True; end; procedure TfMain.VSTExpanding(Sender: TBaseVirtualTree; Node: PVirtualNode; var Allowed: Boolean); begin CollapsingOrExapnding := True; end; procedure TfMain.OnNodeClick(Sender: TObject); begin if not CollapsingOrExapnding then begin //regular node click(not +/- buttons), do something... ShowMessage('ok') end else CollapsingOrExapnding := False; end;

Thanks, yes, this workaround works okay.

Still I am wondering why such a workaround is NodeClick-event should not be fired when nodes are just expanded/collapsed.

I have another VirtualTreeView instance where clicking on a node just selects this node (which VTV does internally). Interestingly, in this case I can collapse/expand without VTV selecting the node. Only if I use the NodeClick-event it is fired together with expand/collapse.

IMO this is a bug.

Reply by email

Balázs Székely
to Jürgen Hestermann
>Still I am wondering why such a workaround is needed at all. >The NodeClick-event should not be fired when nodes are just

expanded/collapsed.
Did you try the OnFocusChanged event instead of OnNodeClick? You can replace the OnNodeClick functionality in most cases(depends on the specific code though).

Reply by email

Jürgen Hestermann
to Balázs Székely
Balázs Székely wrote 6 lines
>> Still I am wondering why such a workaround is needed at all. >> The NodeClick-event should not be fired when nodes are just expanded/collapsed. Did you try the OnFocusChanged event instead of OnNodeClick? You can replace the OnNodeClick functionality in most cases(depends on the specific code though).

Well, yet another workaround.

I think this will not work because when
someone clicks twice on the same node then
OnFocusChanged would not be called (I think)
as the focused node does not change.

Reply by email

Jürgen Hestermann
to Jürgen Hestermann: Thanks, yes, this workaround works okay. Still I am wondering why such a workaround is …
Jürgen Hestermann wrote 25 lines
Am 2016-09-06 um 16:33 schrieb Balázs Székely: > This should work: > procedure TfMain.VSTCollapsing(Sender: TBaseVirtualTree; Node: PVirtualNode; > var Allowed: Boolean); > begin > CollapsingOrExapnding := True; > end; > procedure TfMain.VSTExpanding(Sender: TBaseVirtualTree; Node: PVirtualNode; > var Allowed: Boolean); > begin > CollapsingOrExapnding := True; > end; > procedure TfMain.OnNodeClick(Sender: TObject); > begin > if not CollapsingOrExapnding then > begin > //regular node click(not +/- buttons), do something... > ShowMessage('ok') > end > else > CollapsingOrExapnding := False; > end; Thanks, yes, this workaround works okay.

Unfortunately, this workaround has another side effect because the OnCollapsing/OnExpanding routines are not only called when someone clicks on the buttons but also when I do expand/collapse internally or when VTV does this. Then the boolean variable stays true and the first click on the node does not work.
So I have to again work around the workaround...

I am still wondering why this is needed at all...

Reply by email

Balázs Székely
to Jürgen Hestermann
>I am still wondering why this is needed at all...

TTreeView behaves the same. When you click on the +/- buttons is still considered a node click, because technically you do click a node.

>So I have to again work around the workaround...

What exactly are you trying to achieve on NodeClick? Perhaps it can be replaced with something else.

Reply by email

Jürgen Hestermann
to Balázs Székely
Balázs Székely wrote
>> I am still wondering why this is needed at all... TTreeView behaves the same. When you click on the +/- buttons is still considered a node click, because technically you do click a node.

IMO this is not true.
I am not clicking on the node but on the button to the left of it. When I click on expand/collapse, why should I want to trigger any other function with this?
Also, as already written, when I use the internal functions of VTV to let me *select* a node by clicking on it, then this selection does not happen together with expand/collapse (although in your logic I am clicking on the node too). So why should NodeClick be fired?

>> So I have to again work around the workaround... What exactly are you trying to achieve on NodeClick? Perhaps it can be replaced with something else.

I have a (hierarchical) list of functions which
should be invoked when the user clicks on them.
But of course, arranging the tree of functions
by expanding/collapsing should not fire any of the functions.

I have now a (new) workaround to my problem
so there is no need to look for an alternative solution. Still I think that this behaviour of VTV is a bug.

Reply by email