TreeView is dynamically built by data sheets, absolutely high efficiency!

xiaoxiao2021-03-06  75

/*1. The structure of the database table: (Node ID Node Parent ID (PID) and other fields) ID, PID type does not matter, numbers, characters, no regular, just guarantee the ID field as the main key, such as Guid Come as ID. Support unlimited levels.

2. TTREENODE DATA points to a structure, with a domain record node ID and PID, and other domains can be defined by themselves as needed.

3. Generating a tree from the database, it is necessary to consider, to make efficiency, the most important thing is "avoiding repeated query database or traversal data set", it is best to query once a whole tree. The main thinking is: Mr. became a tree that is all rooted nodes, and then adjusts, so that it avoids reading the child nodes and not find the parent node. * /

Struct nodedata // node associated with data {Int ID; int pid; ansistring name; Ansistring Memo; // Other domain omitted ...};

Void __fastcall fixtree () {struct nodedata * ndata = null; tstringlist * ss = null;

TTREENODE * anode = null; ttreenode * bNode = null; ttreenode * pnode = NULL;

Query1-> close (); query1-> sql-> text = "SELECT ID, PID, NAME, MEMO from Tree_Tab"; query1-> sql-> open ();

转载请注明原文地址:https://www.9cbs.com/read-108802.html

New Post(0)