私のツリーには2つのレベルのノードがあります-それは連絡先リストスタイルのツリーです。
私の問題は、すべての「連絡先カテゴリ」ですべての連絡先をチェックしてもらいたいということです。これが現在の連絡先リストのスクリーンショットです(はい、投稿する権限があります)
ご覧のとおり、Todd Hirschはカテゴリテストカテゴリでチェックされていますが、すべての連絡先ではチェックされていません。私が達成しようとしているのは、連絡先にすべてのカテゴリで同じチェックステータスを持たせることです。
例:テストカテゴリでToddHirschをチェックします-ToddHirschはすべての連絡先(および他のすべてのカテゴリ)で自動的にチェックされます。すべての連絡先でToddHirschをチェックすると、テストカテゴリでもチェックされます。すべての連絡先でToddHirschのチェックを外すと、テストカテゴリでもチェックが外されます。
VirtualStringtreeのOnCheckingイベントを介して、ツリー内の各ノードのツリー全体をループして試してみましたが、連絡先リストが大きい場合(2000以上)は非常に遅く、5000以上の場合はさらに遅くなる可能性があります。プログラムをクラッシュさせます(アプリケーションが動作を停止しました)
何を指示してるんですか?
これは、連絡先が1回だけチェックされるようにするために使用するコードです。(それは私が今望んでいるものではありませんが、私が今使っているものです。)
////////////////////////////////////////////////////////////////////////////////
/// HasDuplicateChecked
////////////////////////////////////////////////////////////////////////////////
Function HasDuplicateChecked(Node: PVirtualNode): PVirtualNode;
Var
ParentNode, ChildNode: PVirtualNode;
I, J: Integer;
Begin
// IHCW
Result := Nil;
// Get the first node of the tree..
ParentNode := VT.GetFirst;
// Loop thru the parent nodes.
for I := 0 to VT.RootNodeCount - 1 do
begin
// Get the first child node.
ChildNode := ParentNode.FirstChild;
// Loop thru the children..
for J := 0 to ParentNode.ChildCount - 1 do
begin
// If the ChildNode is checked...
if NodeIsChecked(ChildNode) then
// And it is NOT the passed node..
if ChildNode <> Node then
// but the data matches..
if GetData(ChildNode).SkypeID = GetData(Node).SkypeID then
begin
// Then pass the Childnode as a result, and EXIT!
Result := ChildNode;
Exit;
end;
// Next child..
ChildNode := ChildNode.NextSibling;
end;
// Next parent...
ParentNode := ParentNode.NextSibling;
end;
End;
////////////////////////////////////////////////////////////////////////////////
/// vtSkypeChecking
////////////////////////////////////////////////////////////////////////////////
procedure TSkypeListEventHandler.vtSkypeChecking(Sender: TBaseVirtualTree;
Node: PVirtualNode; var NewState: TCheckState; var Allowed: Boolean);
Var
Level: Integer;
I: Integer;
Child: PVirtualNode;
begin
// Allow the checking..
Allowed := True;
// Get the Level..
Level := Sender.GetNodeLevel(Node);
// If the level is 0 (Category Level)
if Level = 0 then
begin
// And if the Node's Childcount is more than 0
if Node.ChildCount > 0 then
Begin
// Get the first child..
Child := Node.FirstChild;
// Loop thru the children..
for I := 0 to Node.ChildCount - 1 do
begin
// Set the checkstate, and go next..
Child.CheckState := NewState;
Child := Child.NextSibling;
end;
End;
end;
// If the level is 1 (User Level)
if Level = 1 then
begin
// and if the Node's parent is not Nil..
if Node.Parent <> nil then
begin
// aaand, if the new state is Unchecked...
if (NewState = csUncheckedNormal) or (NewState = csUncheckedPressed) then
begin
// .. and if the node checkstate is checked..
if NodeIsChecked(Node) then
Begin
// Set the PARENT node's checkstate to Unchecked!
Node.Parent.CheckState := csUncheckedNormal;
End;
end;
// BUT, if there is a DUPLICATE of the node, screw the above, and
// forbid the checking!
if HasDuplicateChecked(Node) <> nil then
Allowed := False;
end;
end;
// Uncheck all the duplicates.
UncheckDuplicates;
// Refresh the Tree
Sender.Refresh;
end;