VirtualTreeView: properly handling selection changes
Set the ChangeDelay
property to an appropriate, greater than zero value in milliseconds, e.g. 100
. This implements the one-shot timer Rob Kennedy suggests in his answer.
You forgot OnStateChange event. This event will be fired right after any selection change and you can then handle all selected nodes.
procedure TForm1.vstStateChange(Sender: TBaseVirtualTree; Enter,
Leave: TVirtualTreeStates);
begin
if tsChangePending in Leave then
DoSomething;
end;
Use a one-shot timer. When the timer fires, check whether the selection is different, update your display if it is, and disable the timer. Each time you receive a potential selection-changing event (which I think is always OnChange), reset the timer.
This gives you a way of waiting for the event you really want and avoid flickering. The cost is a slightly delayed UI.