[AccessD] Tina's Treeview example

jwcolby jwcolby at colbyconsulting.com
Fri Feb 27 18:18:08 CST 2009


OMG, combo2?  COMBO2???

I will NEVER look at your code again!!!

;)

John W. Colby
www.ColbyConsulting.com


Drew Wutka wrote:
> Ok, the sample is at http://www.marlow.com/treeview.zip
> 
>  
> 
> In the database, there are three tables (to keep it simple).  tblSkills,
> tblVolunteers and tblVolunteerSkills.
> 
>  
> 
> The first two tables are ID and Name (SkillID and VolunteerID).  The
> third table has both id's and SkillLevel.
> 
>  
> 
> I put a few skills and two volunteers, Bob and Larry.
> 
>  
> 
> There is one form, frmVolunteerSkills.
> 
>  
> 
> It has a Combobox (Combo2...sorry, should have renamed it, but was in a
> rush).  It displays the volunteers (with the bound column being the ID).
> 
>  
> 
> On the Onclick event, it runs a function 'BuildTreeView' and put's it's
> value (the volunteer ID) in the intVolunteerID argument.
> 
>  
> 
> That function opens a recordset from the skills table and creates the
> Nodes.
> 
>  
> 
> Ok, Before I continue, a few things to know about treeviews.  Treeviews
> are a control based around nodes.  Nodes can either be Root Nodes or
> Child Nodes.  You can also display check boxes or even pictures for each
> node.  On top of that, node 'labels' can also be edited (if you want),
> so you can even allow someone to change the text of something. If you
> want an example of how you could allow your user to edit the name of a
> skill from the treeview, let me know.  It takes a little bit of playing
> around with a treeview and it's node objects to get used to them, but
> once you do, it is a very powerful interface tool.
> 
>  
> 
> Back to BuildTreeView.  It builds a root node for each skill, and sets
> it's key to "ID:x" (x being whatever ID the Skill is).  It then builds
> three child nodes with the key of "ID:x:y" where y is 1 through 3 (the
> skill level).
> 
>  
> 
> It then opens another recordset from the tblVolunteerSkills, based on
> the VolunteerID.  It runs through that recordset 'checking' the nodes
> that are applicable (the root node (skill) and the child node (skill
> level), and as you can see in the code, it does this by using the values
> from the table being put in the ID:x and ID:x:y format. (It also expands
> any skill 'root node' that is selected already)
> 
>  
> 
> Now, the treeview itself is handling the data entry, it's doing this in
> tvwSkills_NodeCheck (so it does stuff whenever you 'check' a node).
> Kind of hard to write out what the logic is doing, but here's the gist,
> when you click on a root node (a skill), if you don't have a skill level
> selected, it really does nothing (I have commented out code where I was
> trying to uncheck the node then....wasn't working, and again, this was a
> quick and dirty example, there should be a way to uncheck the node, the
> problem is, stepping through the code, it would uncheck it, but when the
> code finished, the node rechecked itself....odd....).  But if it IS
> checked, so the user is 'unchecking' a skill, it unchecks it's child
> nodes (the skill levels), and deletes the appropriate record in
> tblVolunteerSkills. 
> 
>  
> 
> If you check a skill level, it unchecks any other skill level (so if
> skill level 1 for Cooking is checked, and the user checks skill Level 2
> for cooking, Skill Level 1 for cooking unchecks itself, so it gives the
> illusion of only being able to check one skill level....like a radio
> button option box would...), it then tries to 'update'
> tblVolunteerSkills and if no records return from that, it 'inserts' the
> appropriate record.  It also 'checks' it's parent root node.  
> 
>  
> 
> If you uncheck a skill level, it unchecks it's parent, and deletes the
> appropriate record from tblVolunteerSkills.
> 
>  
> 
> Like I said, this is a quick and dirty example, but it should show what
> you can do with a treeview, and should also satisfy your 'click happy'
> end user! ;)
> 
>  
> 
> Drew
> 
> 
> The information contained in this transmission is intended only for the person or entity to which it is addressed and may contain II-VI Proprietary and/or II-VI Business Sensitive material. If you are not the intended recipient, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. You are notified that any review, retransmission, copying, disclosure, dissemination, or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited.
> 



More information about the AccessD mailing list