|
-
Jun 16th, 2010, 01:30 AM
#1
Thread Starter
Lively Member
[RESOLVED] Vb6, Treeview, checkboxes, returning node caption
Hi,
I'm working with a TreeView with checkboxes. I would like to make something like this:
The user checks like 4 out of 10 nodes, and presses a button. the program then loops through the treeview, outputting the caption of every checked node, 1 at a time (with a timer).
how do i set this up?
Last edited by JWJWJW; Jun 16th, 2010 at 01:31 AM.
Reason: Title
My Programming Software: Visual Basic 2010
My Database Program: Office Access 2010
-
Jun 16th, 2010, 01:39 AM
#2
Re: Vb6, Treeview, checkboxes, returning node caption
In this example i load a TV with data and then, when pressing a commandbutton only the nodes checked are shown in messageboxes. What's the reason to use a Timer? your idea is waiting a certain amount of time between messageboxes?
Code:
Private Sub Form_Load()
With TreeView1
.CheckBoxes = True
.Nodes.Add , , "Root", "Root"
.Nodes.Add "Root", tvwChild, "Child1", "Child1"
.Nodes.Add "Root", tvwChild, "Child2", "Child2"
.Nodes.Add "Root", tvwChild, "Child3", "Child3"
.Nodes.Add "Root", tvwChild, "Child4", "Child4"
.Nodes.Item("Root").Expanded = True
End With
End Sub
Private Sub Command1_Click()
Dim lNode As Node
For Each lNode In TreeView1.Nodes
If lNode.Checked Then
MsgBox lNode.Text
End If
Next
Set lNode = Nothing
End Sub
-
Jun 16th, 2010, 01:53 AM
#3
Thread Starter
Lively Member
Re: Vb6, Treeview, checkboxes, returning node caption
Hi,
No, i want to search a database for that value. since there are no database questions allowed here, i thought timer would have a similar type of code.
Thanks for that code though! i just have 1 more question:
this is what my treeview looks like:
GroupA - product1
- product2
GroupB - product1
- product2
- product3
GroupC - product1
GroupD .etc
When the node of "GroupA" is checked, all child nodes are checked. how can i output (for instance, the way you proposed) only the products, and not the group names?
Thanks!
My Programming Software: Visual Basic 2010
My Database Program: Office Access 2010
-
Jun 16th, 2010, 02:05 AM
#4
Re: Vb6, Treeview, checkboxes, returning node caption
GroupA, GroupB, GroupC..etc, all that nodes are Roots? If so, a possible way to avoid showing them is:
Code:
Private Sub Command1_Click()
Dim lNode As Node
For Each lNode In TreeView1.Nodes
If Not (lNode Is lNode.Root) And lNode.Checked Then
MsgBox lNode.Text
End If
Next
Set lNode = Nothing
End Sub
If Not (lNode Is lNode.Root) Means: If the Root of this node is not this same node.
-
Jun 16th, 2010, 02:10 AM
#5
Thread Starter
Lively Member
Re: Vb6, Treeview, checkboxes, returning node caption
Yes, the group nodes are at the root. all of these groups only have children (so there are no childrens children... no grandchildren ).
Your code of comparing the lnode to lnode.root doesn't work somehow. It still shows GroupC when it's clicked.
My Programming Software: Visual Basic 2010
My Database Program: Office Access 2010
-
Jun 16th, 2010, 02:23 AM
#6
Re: Vb6, Treeview, checkboxes, returning node caption
Oops.. my mistake. Your TreeView only has Group Nodes with Product Nodes (Children)? that's all? or Product children could also have more children? If it is just Group nodes with product children it could be done like this:
Code:
Private Sub Command1_Click()
Dim lNode As Node
For Each lNode In TreeView1.Nodes
If lNode.Children = 0 And lNode.Checked Then
MsgBox lNode.Text
End If
Next
Set lNode = Nothing
End Sub
Last edited by jcis; Jun 16th, 2010 at 02:38 AM.
-
Jun 16th, 2010, 02:28 AM
#7
Re: Vb6, Treeview, checkboxes, returning node caption
Just added 1 more condition in my previous post to make it also work if there are groups without products..
Edited: Nevermind, the code should be changed drastically to make it work when having groups without products, but you said this can never happen so i'll leave it like it is now.
Last edited by jcis; Jun 16th, 2010 at 02:39 AM.
-
Jun 16th, 2010, 02:29 AM
#8
Thread Starter
Lively Member
Re: Vb6, Treeview, checkboxes, returning node caption
Very nice! It works.
Thanks alot! need to finish this program tomorrow evening, so this saved a lot of time!
My Programming Software: Visual Basic 2010
My Database Program: Office Access 2010
-
Jun 16th, 2010, 02:32 AM
#9
Thread Starter
Lively Member
Re: Vb6, Treeview, checkboxes, returning node caption
Yes, i excluded that state when creating the database.
There can never be groups without products, since a group can only be created when a product is created.
Thanks though!
My Programming Software: Visual Basic 2010
My Database Program: Office Access 2010
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|