[AccessD] A simple Treeview to edit data.

Max Wanadoo max.wanadoo at gmail.com
Mon Mar 2 15:09:31 CST 2009


Thanks for that Drew.  There is a lot going on behind the scenes and I will
need to work through your text below.
The program worked fine although I would like to see the code whereby if
there were multiple entries under the main entries (>1 node) and any one of
them was clicked then the main node would be ticked.  IOW  if the nodes were
all closed up I would see ticks in only those where 1 or more nodes were
selected and no ticks where there were zero sub-node selections.  Does that
make sense?  Ticking a sub node would auto-tick the main node and unticking
it would check to see if there were any other sub-nodes ticked and if not,
then it would untick the parent node.

Is that possible?


Max
Ps, sometimes I type so quick that instead of typing Max, it comes out as
Ma.  If you see this as coming from Ma, please do not assume your mother has
just joined the discussion.  I have set up my auto-recognition to ignore
emails that begin "Mum, what the <expletive deleted> are you doing here?"





-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Drew Wutka
Sent: 02 March 2009 16:55
To: Access Developers discussion and problem solving
Subject: [AccessD] A simple Treeview to edit data.

With the interest shown about treeviews, I decided to whip up another
example this morning.

 

As you all know, Access is an awesome RAD tool, that allows you to create
very powerful interfaces.  When it comes to editing 'system'
data, Treeviews will probably fall short.  But where they can really come in
handy (and look pretty cool), is when it comes to editing 'default' data.

 

As an example, I have whipped up states.mdb.
http://www.marlow.com/states.zip

 

To begin with, to deal with the actual data, I used my Data Class Builder (a
VB addon I created a while back).  So the State and AllStates (wouldn't let
me save the class name as States...go figure) are classes that were
automatically generated by my Data Class Builder.  A quick and dirty example
of data classes (and collection).

 

Next, I noticed to actually get to the Treeview's custom dialog box (a
window that let's you get to the Treeview's very flexible custom
properties), when you go into the properties of your ActiveX Treeview
control, go to the 'Other' Tab, and click the ... next to Custom. 

 

Now, after you download the example, take a quick look at tblStates.  An ID
field, then an Abbreviation, FullName, and InUse fields.  I'm sure most of
us have a table like this in one system or another (if not most).

 

Let's give our Users a form to edit this information.  Check out frmStates.

 

Keep in mind, this example database took me about 5 minutes to build.
It's taking longer to write this email then to build this example.
There a quirk that I noticed in testing.  One, if you run into a unique
index issue, it errors, something that a little more code could handle.
So just keep that in mind, that this is an example, not a full blown, ready
to go into production system.

 

When you open frmState, notice that all the records are listed.  (And
everything is checked).  It lists all the states by full name.  If you
expand a node, you get the state's abbreviation.  Uncheck either the
fullname or the abbreviation, and both are unchecked, AND the 'InUse'
flag for that state is now set to false in the table. (Or check an unchecked
state, and the reverse happens)  Cool, eh?  But what if we want to rename a
state.....

 

Click on a state. (either the full name or it's abbreviation.  It becomes
selected (highlighted).  Now click on it again.  (single clicks)....and the
'label' goes into Edit mode.  Type whatever you want in that label. (Keep in
mind that both the fullname and abbreviation fields are unique indexes, so
you can't make FLORIDA 'MAINE', it'll choke.  But you could rename florida
to 'Can't Decide'. <grin>.  When you are done typing in what you want to
rename the state too, just hit enter.  It goes out of edit mode....and the
new data is saved to the appropriate field!  (Go check the table!).

 

The InUse is handled by the NodeCheck event for the treeview, and the field
renaming is handled by the AfterLabelEdit event.

 

There is another really nice advantage to Treeviews, and I've added this to
this example.  Sometimes you want the user to be able to resize a form.  And
when you have lots of controls on a form, that's a lot of controls to
resize.  With the 'all in one' ability of a treeview control (the ability to
handle multiple purposes in the same control), you only have one control to
resize!  Resize the frmStates form, and you'll see it only takes two lines
of code to keep that form looking nice, neat, and uniform!

 

Drew





More information about the AccessD mailing list