[AccessD] Tina's Treeview example

Drew Wutka DWUTKA at Marlow.com
Sat Feb 28 14:51:31 CST 2009


Glad you like it Tina.  I will warn you that the demo I posted for you
is just the tip of the iceberg when it comes to what you can do with a
treeview.

A great example is 'HitTest'.  It's a method of the Treeview control,
where you give it x,y coordinates, and it returns the node at the
coordinates.  This allows you to create custom behaviors for left and
right clicks (Mouse Up event gives you the x,y coordinates).  Where you
could use that in your system, you could actually start the root nodes
as the Volunteers.  And then have the child nodes be the skills and
levels.  The normal left click could have you 'check' if the skill nodes
are built (and if not, build them, so you don't building thousands of
nodes from the get go...), and the right click could display a popup
menu such as 'edit volunteer information' or 'create a new skill', etc.

Here's a visual example of one of the most highly used treeviews I have
built:

http://www.marlow.com/PhoneList.jpg

That screen shot (I blurred the phone numbers...) shows what you can do
with the image capabilities of a treeview.  I've right clicked my name,
showing the custom popup menu that displays (based on the node that was
clicked).  One of the expanded nodes is Currently logged on computers,
if I expand one of those nodes, it gives me Remote Administrator
(clicking on that node opens a remote admin session to that machine),
computer management (clicking on that node opens a computer management
session to that computer), local drives (expanding that node gives me a
list of the local drives on that machine, which I can click to open a
Windows Explorer session to that drive).

All from one treeview!

Good luck with your project (feel free to holler if you have any
questions about what I did...)!  Next to classes and collections, I've
found Treeviews to be one of the most powerful tools in a developer's
arsenal!

Drew



-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Tina Norris
Fields
Sent: Saturday, February 28, 2009 9:36 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Tina's Treeview example

Wow, Drew!  Okay, I think I love it.  Now, I need to walk my way through

all the code to make sure I understand it.  Thanks a bunch!
Tina

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.
>
>   
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
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