2016-12-17 10 views
0

私はtcxtreelistを持っています 誰もチェックノードを取得する方法を知っていますか?私は がtcxtreelist から一定の値を取得し、カンマで文字列にそれを書く私のtcxtreelistを通過する必要がありチェックノードをtcxtreelistから取得する

誰もがこれで私を助けることができる区切り?

おかげで 種類よろしく

答えて

1

あなたはcxTreeList 3の列、colCheckedcolYearcolMonthがあるとします。あなたはIDEでcolCheckedに行けば

は、あなたが CheckBoxにそのPropertiesプロパティを設定すると、実行時に、チェックボックスとして使用することができます。

特定のツリーノードのChecked値を取得する方法は、実際には非常に簡単です。あなたは、変数Node : TcxTreeList nodeを宣言すると は、あなたがアクセスし によってノードの3つの列の値で取得することができ、それをやった

Node := cxTreeList1.Items[i]; 

のように、ツリー内の任意の のノードに割り当てることができますValuesノードのプロパティは、ノードに格納されツリーに表示されている値を表す0から始まるバリアントの配列 です。 だから、あなたは

var 
    Node : TcxTreeListNode; 
    Checked : Boolean; 
    Year : Integer; 
    Month : Integer; 

begin 
    Node := cxTreeList1.Items[i]; 
    Checked := Node.Values[0]; 
    Year := Node.Values[1]; 
    Month := Node.Values[2]; 
end; 

を書くことができ、当然、あなたは反対 方向に割り当てによって、ノードのValuesを設定することができます(ただし、表示されたので、DB対応バージョン、TcxDBTreeListとそれをしようとしないでください値は、それに接続されたデータセットのフィールド の内容によって決定されます)。

Nodeローカル変数を使用する必要はありません。明確にするためにのみ使用しています。あなたは同じように簡単に(ではないので、はっきりと)

Checked := cxTreeList1.Items[i].Values[0] 

書くことができますここでチェックボックス欄でcxTreeListを設定し、いくつかのサンプルコードでは、だ行を移入し、チェックボックスをチェックしていた行のリストを生成します:

uses 
    [...]cxTLData, cxDBTL, cxInplaceContainer, cxTextEdit, 
    cxCheckBox, cxDropDownEdit; 

type 
    TForm1 = class(TForm) 
    cxTreeList1: TcxTreeList; 
    Memo1: TMemo; 
    btnGetCheckedValues: TButton; 
    procedure btnGetCheckedValuesClick(Sender: TObject); 
    procedure FormCreate(Sender: TObject); 
    private 
    protected 
    colChecked : TcxTreeListColumn; 
    colYear : TcxTreeListColumn; 
    colMonth : TcxTreeListColumn; 
    public 
    procedure GetCheckedValues; 
    end; 

[...] 
procedure TForm1.FormCreate(Sender: TObject); 
var 
    i : Integer; 
    Year, 
    Month : Integer; 
    YearNode, 
    MonthNode : TcxTreeListNode; 
begin 
    cxTreeList1.BeginUpdate; 
    try 
    // Set up the cxTreeList's columns 
    colChecked := cxTreeList1.CreateColumn(Nil); 
    colChecked.Caption.Text := 'Checked'; 
    colChecked.PropertiesClassName := 'TcxCheckBoxProperties'; 

    colYear := cxTreeList1.CreateColumn(Nil); 
    colYear.Caption.Text := 'Year'; 

    colMonth := cxTreeList1.CreateColumn(Nil); 
    colMonth.Caption.Text := 'Month'; 

    // Set up the top level (Year) and next level (Month) nodes 
    for Year := 2012 to 2016 do begin 
     YearNode := cxTreeList1.Root.AddChild; 
     YearNode.Values[0] := Odd(Year); 
     YearNode.Values[1] := Year; 
     for Month := 1 to 12 do begin 
     MonthNode := YearNode.AddChild; 
     MonthNode.Values[0] := False; 
     MonthNode.Values[1] := Year; 
     MonthNode.Values[2] := Month; 
     end; 
    end; 

    finally 
    cxTreeList1.FullExpand; 
    cxTreeList1.EndUpdate; 
    end; 
end; 

procedure TForm1.GetCheckedValues; 
var 
    i : Integer; 
    Node : TcxTreeListNode; 
    S : String; 
begin 
    for i := 0 to cxTreeList1.Count - 1 do begin 
    Node := cxTreeList1.Items[i]; 
    if Node.Values[0] then begin 
     S := Format('Item: %d, col0: %s col1: %s col2: %s', [i, Node.Values[0], Node.Values[1], Node.Values[2]]); 
     Memo1.Lines.Add(S); 
    end; 
    end; 
end; 

procedure TForm1.btnGetCheckedValuesClick(Sender: TObject); 
begin 
    GetCheckedValues; 
end;