首页 > 代码库 > cxDBTreelist一些使用方法

cxDBTreelist一些使用方法

一、导出EXCEL   TXT   HTML:

uses cxTLExportLink;

 

cxExportTLToEXCEL(dm.SaveDialog.FileName,cxDBTreeList1,TRUE,TRUE);  //轉入EXCEL
cxExportTLToTEXT(dm.SaveDialog.FileName,cxDBTreeList1,TRUE,TRUE);     //轉入TXT
cxExportTLToHTML(dm.SaveDialog.FileName,cxDBTreeList1,TRUE,TRUE);     //轉入HTML

技术分享

 

--------------------------------------------------------------------------------------------------------------- 

二、cxdbtreelist1共多少条记录:     showmessage(inttostr(cxtreelist1.VisibleCount));

       cxdbtreelist1当前记录的索引:  showmessage(inttostr(cxTreeList1.FocusedNode.VisibleIndex));

       cxdbtreelist1有多少列:             showmessage(inttostr(cxtreelist1.VisibleColumnCount));

       cxdbtreelist1当前记录的层级:   showmessage(inttostr(cxTreeList1.FocusedNode.Level));

       cxdbtreelist1自动展开:             cxtreelist1.fullexpand; //自动展开

       cxdbtreelist1自动折叠 :               cxtreelist1.FullCollapse;

       cxdbtreelist1取上级节点内容:   ShowMessage(cxdbTreeList1.FocusedNode.Parent.Values[0]);

 

三、新增、删除结点:

增加同级结点:

procedure Tfr_bommglin.cxButton1Click(Sender: TObject);
var node:TcxTreeListNode;
begin

   node:=cxdbTreeList1.FocusedNode.Parent.AddChild;
   node.Values[0]:=‘aaaaa‘;
   node.Values[1]:=node.Level;

end;

 

增加下级节点:

procedure Tfr_bommglin.cxButton2Click(Sender: TObject);
var node:TcxTreeListNode;
begin
   node:=cxdbTreeList1.FocusedNode.AddChild;       //增加子节点在首记录:cxdbTreeList1.FocusedNode.AddChildFirst;
   node.Values[0]:=‘aaaaa‘;
   node.Values[1]:=node.Level+1;
   cxdbTreeList1.FocusedNode.Expanded:=true;  //展开子节点
end;

 

 删除节点:

ClientDataSet1.GetBookmark;
cxdbTreeList1.FocusedNode.Delete;     //删除当前节点记录;删除当前节点的子节点:cxdbTreeList1.FocusedNode.DeleteChildren;
cxDBTreeList1.DataController.GotoBookmark;

多节点选择删除:

cxDBTreeList1.DeleteSelection

 

数据集控制:

cxDBTreeList1.DataController.dataset.GotoFirst; //GotoLast     gotonext    gotoprev   GotoBookmark

cxDBTreeList1.DataController.dataset.Append;         //cancel      updatedata

cxDBTreeList1.DataController.dataset.edit;

根据cxdbtreelist随clientdataset1记录定位:

首先:bl:=cxDBTreeList1.DataController.DataSet.GetBookmark;

接着:cxDBTreeList1.DataController.DataSet.GotoBookmark(bl);
          cxDBTreeList1.SetFocus;

 

   

 

多结点选择取记录:

  for i:=0 to cxDBTreeList1.SelectionCount-1 do
     begin
       ShowMessage(cxDBTreeList1.Selections[i].Values[1]);
    end;

 

-------------------------------------------------------------------------------------------

 三、增加节点图片:

        先在窗体上放ImageList关联到cxDBTreeList,在cxDBTreeList的GetNodeImageIndex事件中写如下:

  procedure cxDBTreeList1GetNodeImageIndex(Sender:TcxCustomTreeList; ANode: TcxTreeListNode; AIndexType:
                       TcxTreeListImageIndexType; var AIndex: TImageIndex);
 var
    i :Integer;
  begin
    //给树结点加上图标
    for i := 0 to ANode.ValueCount do
      begin
     if ANode.Level = 0 then
         begin
           ANode.ImageIndex := 0;
         end
       else
       if ANode.Level = 1 then
         begin
           ANode.ImageIndex := 2;
         end
       else
       if ANode.Level = 2 then
         begin
           ANode.ImageIndex := 1;
         end;
     end;
 end;

cxDBTreelist一些使用方法