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;


實現 cxTreeList使用復選框實現多選 自動級聯選擇

var
  RootNode,SonNode:TcxTreeListNode;
  qryRoot,qrySon:TADOQuery;     
  
  cxTreeList1.OptionsView.CheckGroups:=true;
  cxTreeList1.Root.CheckGroupType:=ncgCheckGroup;  
  qryRoot:=TAdoQuery.create(nil);  
  qrySon:=TAdoQuery.create(nil);  
  qryRoot.Connection:=con1; 
 qrySon.Connection:=con1;  
 try     
 with qryRoot do   
 begin      
	 Close;		  
	 SQL.Text:='SELECT DISTINCT  PID,Caption FROM dbo.Parent';
	 Open;
      qrySon.Close;
      qrySon.SQL.Text:='SELECT PID,SID,Caption FROM dbo.Son  ORDER BY PID,SID';
      qrySon.Open;
      cxTreeList1.Clear;
      DisableControls;
      while not eof do     
 	  begin        
	    RootNode:=cxTreeList1.Add;
        RootNode.CheckGroupType:=ncgCheckGroup;
        RootNode.Texts[0]:=FieldByName('PID').AsString+'.'+FieldByName('Caption').AsString;
        RootNode.Texts[1]:=FieldByName('PID').AsString;
        RootNode.Enabled:=False;
        with qrySon do        begin          DisableControls;
          Filtered:=False;
          Filter:='PID='+QuotedStr(FieldByName('PID').AsString);
          Filtered:=True;
          while not Eof  do        
		  begin            
		    SonNode:=RootNode.AddChild;
            SonNode.Texts[0]:=trim(FieldByName('SID').AsString)+'.'+FieldByName('Caption').AsString;
            SonNode.Texts[1]:=trim(FieldByName('SID').AsString);
            Next;
          end;
          EnableControls;
        end;
        Next;
      end;
      EnableControls;
    end;
  finally    
    qryRoot.Free;
    qrySon.Free;
  end;

  


獲取CxDBTreeList所有父節點

function  ShowCxDBTreeListNodeValues(ACxDBTreeList: TcxDBTreeList): string; 
var 
S:string; 
aNode:TcxTreeListNode; 
i:Integer; 
begin 
  if ACxDBTreeList.Visible then 
    if ACxDBTreeList.FocusedNode.HasChildren then //只顯示最底層,如果要顯示全部  去掉這個條件
     Exit; 
  aNode:=ACxDBTreeList.FocusedNode; 
  for i:=aNode.Level downto 0 do 
  begin 
  if i=ACxDBTreeList.FocusedNode.Level then 
    S:=aNode.Values[1] 
  else 
    S:=aNode.Values[1]+'->'+S; 
  aNode:=aNode.Parent; 
  Result:=S; 
  end; 
end;


 

1,在cxTreeList的treeview內添加的checkbox能否設置一下實現不聯動? 我現在選中2,其子節點也全部被選中了,我想實現一個一個的單獨可以選中,就是所有子節點全部被選中,其父節點也不跟隨子節點的狀態變化。 2,把cxTreeList某一列的properties的屬性設置為RadioGroup,Items內只設置了一個值“允許” 我如何能動態設置RadioButton的選中狀態? 當然properties的屬性也可以設置為CheckBox,使用Newnode.Values[3] := False;就可以設置checkbox為非選中狀態,但我是想學習一下RadioGroup的用法。

咋自動選中子節點的? 俺這兒想盡了辦法都選不中子節點 大哥指點俺一下! 就是你那個聯動咋弄上去的?

 cxTreeList1.OptionsView.CheckGroups := True;  cxTreeList1.Root.CheckGroupType := ncgCheckGroup; var NewNode: TcxTreeListNode; begin   NewNode:=cxTreeList1.Add;   NewNode.CheckGroupType :=  ncgCheckGroup;

頂頂,再幫忙看看

幫忙看看,來個回復也好啊,如何讓我結貼呢

CheckGroupType := ncgCheckGroup; 除了這種屬性,還有另一種類似 RadioGroup的方式。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM