| |

VerySource

 Forgot password?
 Register
Search
View: 1098|Reply: 7

Solving: Adding nodes to Treeview with loop

[Copy link]

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Germany

Post time: 2020-2-5 10:30:01
| Show all posts |Read mode
There are several node variables:
Variable node name path
item (1) Root Root
item (2) 1st_1 Root\1st_1
item (3) 1st_2 Root\1st_2
item (4) 1st_2 Root\1st_2\1st_2
(The above variables, including the full path, are known and can be directly referenced)


The resulting tree shape is:
Root
  | --- 1st_1
  |
  | ___ 1st_2
        | ___ 1st_2

Require to loop through 4 variables, and then add each variable to the tree according to its path attribute
The problems encountered are mainly
1. 1st_2 has duplicates, although not in the same path, so the key cannot use the node name, how to set the key value in the loop
2. How to specify the parent node when adding with Set mnode = TreeView1.Nodes.Add () method?

If there is a detailed source code for the use of Treeview, please provide a reference ~~~
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-24 16:15:01
| Show all posts
Set mnode = TreeView1.Nodes.Add (parent node ,, ..)
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Germany

 Author| Post time: 2020-3-25 02:00:01
| Show all posts
The key is how to do it with loops? Can I use the key value in TreeView1.nodes.add (...) and let him find it automatically? But I tried it, it seems that it is worthwhile not to set a key. The subsequent child nodes do not know how to specify the parent node.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-4-1 08:00:01
| Show all posts
Set nodX = TreeView1.Nodes.Add (,, "R", "Root")
   Set nodX = TreeView1.Nodes.Add ("R", tvwChild, "C1", "1st_1")
   Set nodX = TreeView1.Nodes.Add ("R", tvwChild, "C2", "1st_2")
   Set nodX = TreeView1.Nodes.Add ("C2", tvwChild, "C3", "1st_2")
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Germany

 Author| Post time: 2020-4-4 11:45:01
| Show all posts
Thank you for your reply, but this method is based on the determination of several (4) nodes, a sentence of input, the method after setting the key value, the question now is if not sure?
I want to use For each .. loop, and then add to the corresponding node according to the path information? How to do it?
Reply

Use magic Report

1

Threads

21

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 Great Britain

Post time: 2020-4-15 11:30:02
| Show all posts
Set nodX = TreeView1.Nodes.Add (,, "R", "Root")
   Set nodX = TreeView1.Nodes.Add ("R", tvwChild, "C1", "1st_1")
   Set nodX = TreeView1.Nodes.Add ("R", tvwChild, "C2", "1st_2")
   Set nodX = TreeView1.Nodes.Add ("C2", tvwChild, "C3", "1st_2")

I said on the basis of the above code, first of all, where does your node come from? If it is from the data, it is easy to match the unique key.

The method to find the key depends entirely on your logic
You can take the first character according to the path
R
R1
R2
 R22
If the current key is not unique, you can R22_1 like this
Completely depends on your logic, because you can directly find a node by key, this is a good tool for you to judge node
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Germany

 Author| Post time: 2020-5-1 15:30:01
| Show all posts
In other words, the key value must be set manually, and it cannot be automatically increased as in the database. Then, when adding new child nodes, it is also necessary to specify the key value of the parent node, not his name.
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-6-3 12:00:01
| Show all posts
I've done it myself~~!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list