[控件]DevExpress删除TreeList已选择的节点

来源于研究分享,有能起到帮助的就默默的感谢下他吧哈!

	// 删除TreeList已选择的节点
procedure TreeListDeleteChecked(ATreeList: TcxCustomTreeList); overload;
procedure TreeListDeleteChecked(ANode: TcxTreeListNode); overload;

procedure TreeListDeleteChecked(ATreeList: TcxCustomTreeList);
var
  ANode, ARoot: TcxTreeListNode;
  i: Integer;
begin
  if ATreeList = nil then
    exit;

  ANode := ATreeList.FocusedNode;
  if ANode = nil then
    exit;

  if (ANode.CheckState in [cbsChecked]) then
  begin
    ANode := ATreeList.FocusedNode.getPrevSibling;
  end;

  ATreeList.BeginUpdate;
  try
    for i := ATreeList.Count - 1 downto 0 do
    begin
      ARoot := ATreeList.Items[i];
      if ARoot.CheckGroupType = ncgCheckGroup then
      begin
        if (ARoot.CheckState in [cbsChecked]) then
        begin
          ARoot.Delete;
        end
        else if (ARoot.CheckState in [cbsGrayed]) then
        begin
          TreeListDeleteChecked(ARoot); // 调用递归删除节点
        end;
      end;
    end;

  finally
    if ANode <> nil then
      ATreeList.FocusedNode := ANode;
    ATreeList.EndUpdate;
  end;
end;

procedure TreeListDeleteChecked(ANode: TcxTreeListNode);
var
  i: Integer;
  tmpNode: TcxTreeListNode;
begin
  if ANode = nil then
    exit;
  for i := ANode.Count - 1 downto 0 do
  begin
    tmpNode := ANode.Items[i];
    while tmpNode <> nil do
    begin
      if tmpNode.CheckGroupType = ncgCheckGroup then
      begin
        if (tmpNode.CheckState in [cbsChecked]) then
        begin
          tmpNode.Delete;
        end;
      end;
      if tmpNode <> nil then
      begin
        if tmpNode.HasChildren then
        begin
          tmpNode := tmpNode.GetNext;
        end
        else
        begin
          tmpNode := nil;
        end;
      end;
    end;
  end;
end;

 

分享到:

0 条评论

注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。

昵称

沙发空缺中,还不快抢~