私は tcxtreelist を持っています。checkedNodes をすべて取得する方法を知っている人はいますか?
tcxtreelist を調べて、tcxtreelist から特定の値を取得し、それをコンマ区切りの文字列に書き込む必要があります
誰でもこれで私を助けることができますか?
よろしくお願いします
私は tcxtreelist を持っています。checkedNodes をすべて取得する方法を知っている人はいますか?
tcxtreelist を調べて、tcxtreelist から特定の値を取得し、それをコンマ区切りの文字列に書き込む必要があります
誰でもこれで私を助けることができますか?
よろしくお願いします
cxTreeList
と の3 つの列がある があるcolChecked
とcolYear
しますcolMonth
。
IDE に移動するとcolChecked
、そのProperties
プロパティを に
設定しCheckBox
、実行時にチェックボックスとして使用できます。
Checked
特定のツリー ノードの値を取得する方法は、実際には非常に簡単です。variable を宣言するとNode : TcxTreeList node
、次のように、ツリー内の任意のノードに割り当てることができます。
Node := cxTreeList1.Items[i];
これが完了すると、ノードのプロパティにアクセスすることで、ノードの 3 つの列の値を取得でき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
by 割り当てを反対方向に設定することもできます (ただし、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;