获取当前界面中Virtualstringtree有效显示区域中的pvirtualnode的列表

function Getnowshowpvirnodelist(
  nowvst: TVirtualStringTree): TList<PVirtualNode>;
var
  cn:Integer;
  toppvnode,botmpvnode:PVirtualNode;
  pvirnodelists:TList<PVirtualNode>;
begin
  Result:=nil;
  toppvnode:=nowvst.TopNode;
  if toppvnode=nil then
    Exit;
  pvirnodelists:=TList<PVirtualNode>.Create;
  if nowvst.BottomNode<>nil then
    botmpvnode:=nowvst.BottomNode
  else
  begin
    botmpvnode:=nowvst.rootnode.LastChild;
    cn:=0;
    repeat
      if nowvst.Expanded[botmpvnode] then
      begin
        botmpvnode:=botmpvnode.LastChild;
      end
      else
        cn:=1;
    until (cn>0);
  end;

  cn:=0;
  try
    repeat
      pvirnodelists.Add(toppvnode);
      if nowvst.Expanded[toppvnode] then   //当前节点含子节点且打开
        toppvnode:=toppvnode.FirstChild
      else
      begin
        if toppvnode.NextSibling=nil then  //某个父节点下最后一个子节点,
        begin                              //查找父节点的下一个节点
          if toppvnode.Parent=nowvst.RootNode then //是否为最高节点
          begin
            Break;
          end
          else
          begin
            toppvnode:=toppvnode.Parent;
            toppvnode:=toppvnode.NextSibling;
            if toppvnode=nil then
              Break;
          end;
        end
        else
        begin
          if toppvnode.NextSibling=botmpvnode then
          begin
            pvirnodelists.Add(botmpvnode);
            Break;
          end
          else
            toppvnode:=toppvnode.NextSibling;
        end;

      end;
    until (cn>10);

    Result:= pvirnodelists;
  except
    cn:=1;
  end;
end;

 

posted @ 2020-09-15 10:21  大青椒  阅读(162)  评论(0)    收藏  举报