Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiselect checkboxes on a treeview control

Status
Not open for further replies.

cristobalito

Technical User
Dec 20, 2001
12
0
0
GB
Hello, has anyone managed to multi select on a treeview control? I want to create a treeview with checkboxes so that if a parent node is 'checked' all the child nodes are automatically checked. then i want to be able to save all the checked nodes, parents and children, as a record in my database. any direction and help would be great..
 
This may help. I'm not sure which point you're at, so I'll just give you the unabridged version. Make your tables with one field for each parent or child, and make the type of each of these yes/no. Generate your form based on this table, and lay out the resulting checkboxes as you want them. sounds like you've already got this far. Then, add the following code to the form's module for each of the parent boxes.

Private Sub chkParent1_AfterUpdate()
If chkParent1.Value=True Then
chkChild1.Value=True
chkChild2.Value=True
chkChild3.Value=True
Else
chkChild1.Value=False
chkChild2.Value=False
chkChild2.Value=False
Endif
End Sub

I figure it's possible you wanted something to do with subforms, or dynamically generated lists, but if not this should work
 
Hello iainm

thank you very much for your suggestion. I do not want to strain your patience and help, however, i'm not as far on as you think! I'm not sure how to generate the table you suggested and then the accompanying form! If you can offer help here as well I could then go on to try and use the code above...

i hope to hear from you soon,
kindest regards
cristobalito
 
Whoops! sorry, it's taken me a while to reply. Okay, what you need to do is create a table to store your data. Make a new database and go to the database's main window. Press the "new" button, and select "design view. Add a new line to the table for each parent and child node you want. Set the data type for each line to "Yes/No". doesn't matter what description you give them, it's mostly for your benefit. Now you need to create a new table. This time, use a table wizard. For the record source, select the table you just created, and when it asks you what field you want, add them all. Then when you're asked, say you want to design the form, not open it. You should have a form with a bunch of checkboxes. Arrange them how you want - if you want them to hide and expand, you'll need more help than me I'm afraid. Then, when you've got them all lined up properly, right click on a parent node, and view the properties. In the properties window, select the Event tab, and go to the AfterUpdate box. You should have a button to the right of this box with ... in it. click this, select code builder and you will be given a window with text that looks like this
Option Compare Database

Private Sub Parent1_AfterUpdate()

End Sub

in between the private sub and end sub, add the following code

Private Sub Parent1_AfterUpdate()
If Parent1.Value=True Then
Child1.Value=True
Child2.Value=True
Child3.Value=True
Else
Child1.Value=False
Child2.Value=False
Child3.Value=False
Endif
End Sub


Replace the child1 2 & 3 with whatever you named the children in your table. Stir and Repeat

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top