TAdvTreeView Delete Node Event

Hello!

Is there a Delete Node event exist?
In event list it absent.

Hi, 


There is no feature that allows deleting a node via interaction.
No, no...
I mean, how to delete my data structures, that are attached to Node->DataPointer when i change tree structure?

I need to detect node deletion event to delete my data structure

At which point exactly does the node structure changes? You should have full control over when a node changes.


I create a tree. A attaches my data structures to each node.
After that, some branches i can change: delete, increase or shorten.
Accordingly, I must first delete the previously created data structures and create new structures 
for the new nodes.
For this, I need to hook the node deletion event (in case of deletion) and delete the data structures referenced by Node->DataPointer.

You should consider using the treeview in virtual mode, where you can directly use your datastructure mapped on the treeview. Using this technique, you shouldn't use DataPointer and then you don't need to worry about dangling pointers.


I create my data structure through "new" operator. 
Accordingly, when i delete a node, i must also delete the data structure by "delete" operator.
This structure have a many variables for my purposes.
So, i have to work with DataPointer...

No, you should work with virtual mode.

You should map your data directly on the treeview.

Please use the following documentation guide to apply virtual mode.
http://www.tmssoftware.biz/download/manuals/TMS%20Advanced%20TreeView.pdf
Deleting data in your structure will apply to the virtual mode without using DataPointer.

Pieter, i think there is small missunderstanding...

There is small example of my data structure:

typedef struct{
int a;
int b;
char data1[1024];
double data2[2048];
}my_struct;

This data should not be displayed in the tree. They must be hidden.

How i can attache it to each node of tree?



Hi, 


It's still unclear where the issue is you encounter, even when using DataPointer, you have full control over the nodes collection so you can remove the DataPointer reference at any time. Can you provide a sample that demonstrates where you should have a need to remove a pointer to your data?

Hi,

in Delphi the is an "OnBeforeDropNode", is this what you are searching for?

Greetings from germany
 Peter Nomden


Hi! Here some small example:

typedef struct{
int a;
int b;
char c[1024];
}my_struct;
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender){
TAdvTreeViewNode *atn;
my_struct *ms;

AdvTreeView1->BeginUpdate();
AdvTreeView1->ClearColumns();
AdvTreeView1->ClearNodes();

AdvTreeView1->ColumnsAppearance->TopFont->Size = 8;
AdvTreeView1->NodesAppearance->Font->Size = 8;
AdvTreeView1->NodesAppearance->ExtendedFont->Size = 8;

AdvTreeView1->Columns->Add()->Text = "Column 1";
AdvTreeView1->Columns->Add()->Text = "Column 2";
AdvTreeView1->EndUpdate();

//root node
atn = AdvTreeView1->AddNode(NULL);
atn->Text[0] = _D("Node ") + IntToStr(atn->VirtualNode->Level);
atn->Text[1] = _D("Node ") + IntToStr(atn->VirtualNode->Level);

ms = new my_struct;
ms->a = 100;
ms->b = 101;
for(int i = 0; i < sizeof(ms->c); i++) ms->c = i;
atn->DataPointer = (my_struct *)ms;

atn = AdvTreeView1->AddNode(atn);
atn->Text[0] = _D("Node ") + IntToStr(atn->VirtualNode->Level);
atn->Text[1] = _D("Node ") + IntToStr(atn->VirtualNode->Level);
ms = new my_struct;
ms->a = 200;
ms->b = 201;
for(int i = 0; i < sizeof(ms->c); i++) ms->c = i;
atn->DataPointer = (my_struct *)ms;

atn = AdvTreeView1->AddNode(atn);
atn->Text[0] = _D("Node ") + IntToStr(atn->VirtualNode->Level);
atn->Text[1] = _D("Node ") + IntToStr(atn->VirtualNode->Level);
ms = new my_struct;
ms->a = 300;
ms->b = 301;
for(int i = 0; i < sizeof(ms->c); i++) ms->c = i;
atn->DataPointer = (my_struct *)ms;

AdvTreeView1->ExpandAll();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender){
AdvTreeView1->ClearNodes();
//after this i reconstruct AdvTreeView...
}
//---------------------------------------------------------------------------

When the button is pressed, the cleaning is performed in this case (but there can be only one branch cleaning). How do I clear all pointers to my_struct when clearing? There is an OnDeletion event in the Classic TreeView component... In this event, I deleted the pointer to the structure for each deleted node. And what about AdvTreeView?



Hello! I see "OnBeforeDropNode" is only for drop process... There is "AFromNode" and "AToNode" parameters... This event is not triggers when deleting nodes...

Hi, When calling ClearNodes, you should manually loop through the nodes and clear the DataPointer first. There is no OnDeletion event. And we do not call events when programmatically clearing nodes.


It's a pity. 
Thanks for you answer!