Drew Wutka
DWUTKA at Marlow.com
Mon Mar 2 10:54:40 CST 2009
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 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.