VirtualTreeView: properly handling selection changes

后端 未结 4 812
自闭症患者
自闭症患者 2021-02-02 01:26

This question will seem obvious to those who haven\'t encountered the problem themselves.

I need to handle selection changes in VTV. I have a flat list of nodes. I need

4条回答
  •  我在风中等你
    2021-02-02 02:03

    I assume that you might have used the answers given here or even found another solution but I would like to contribute a bit here...

    In a NON-Multiselect environment (I have not tested it in a multi-select environment) I have found a quite simple solution without the delay:

    Keep a global PVirtualNode pointer (Lets call it FSelectedTreeNode). On startup obviously you will assign nil to it.

    Now eveytime you use your arrow keyboard keys to select the next node the OnTreeChange will happen twice. Once for the node that will be deselected and once for the newly selected node. In your OnTreeChange event you do the following:

      If Node <> FSelectedTreeNode then
        begin
          FSelectedTreeNode := Node;
          If Node = nil then
            {Do some "Node Deselected" code}
          else
            {Do whatever you want to do when a new node is selected}
        end;
    

    This works quite well with my code and it has no flicker and at least no delay.

    The trick is that the newly selected node will be assigned to the global pointer and it will happen last. So when you select another node afterwards it will not do anything on the first OnTreeChange because then the global pointer will be the same as the node being deselected.

提交回复
热议问题