Reputation: 33
Can someone explain to me why this is happening to me? I have this TVirtualStringTree:
As you can see, three nodes have been selected. I traverse the tree to delete the selected records with this loop:
PVirtualNode Nodo;
AnsiString cAux = "";
Query->Close();
Query->SQL->Text = "DELETE FROM Recibos WHERE CodPrv = :PrvIns AND RefInt = :RefInt AND ForPago = :Forma AND Junta = :Junta";
Nodo = Lista->GetFirst();
while (Nodo != NULL)
{
cAux = ((PTreeSelRec)Lista->GetNodeData(Nodo2))->Dato;
if (!Lista->HasChildren[Nodo] && Lista->CheckState[Nodo] > csUncheckedPressed)
{
try
{
Query->Close();
Query->ParamByName("PrvIns")->AsString = PrvIns;
Query->ParamByName("RefInt")->AsString = ((PTreeSelRec)Lista->GetNodeData(Nodo))->RefInt;
Query->ParamByName("Forma")->AsInteger = ((PTreeSelRec)Lista->GetNodeData(Nodo))->ForPago;
Query->ParamByName("Junta")->AsInteger = StrToInt(((PTreeSelRec)Lista->GetNodeData(Nodo))->Concepto);
Query->ExecSQL();
Query->Transaction->Commit();
}
catch(...)
{
fForBln->Hide();
Screen->Cursor = crArrow;
Query->Transaction->Rollback();
ShowMessage("Ha tenido lugar un error en el borrado de recibos.");
Application->ProcessMessages();
return;
}
}
Nodo = Lista->GetNext(Nodo);
}
I have set up with the debugger to tell me the values of HasChildren and CheckState. At no time do I modify, as you can see, the CheckState property of the nodes; however, when I start traversing the tree, the HasChildren property gives me the correct values (three times true and once false) but CheckState, when it enters the last level of each node (Tomelloso in the example), is only set to 0 (csUncheckedNormal). This is what the debugger returns:
As you can see, the first three times it takes the correct values: 10/01/2022, Ordinaries, Unknown. In all three cases HasChildren appears as true because in all three cases there is a child and CheckState as csCheckedNormal because the entire node is selected. But as soon as List->GetNext(Node) is done to take the TOMELLOSO value, without the code doing anything CheckState is set to csUncheckedNormal and, of course, the query is not executed.
I've tried forcing all nodes to expand (List->FullExpand()) but that doesn't work either; It only works well if before pressing the corresponding button the user manually displays the selected node, which is not very logical.
It seems that when the tree has more than three levels, not all nodes behave in the same way. What could I be doing wrong or what property of the object would I want to modify?
Upvotes: 0
Views: 55