Sign in to follow this  
Rifle_001

Adding TreeView Control Items (VB)

Recommended Posts

I'm writing an application that uses a TreeView control to sort (and display when the user clicks on a certain Item) a bunch of profiles, but they're created at run-time by the user (well, loaded at run time, the information is read from external .txt files) and so I need to be able to add TreeViewItems via code. I've searched through numerous Visual Basic references (including the one on MSDN) and I can't find the answer anywhere. So, without all the extra stuff, what I need to know is how to create new items on my TreeView control via Visual Basic code. If you have any questions about my question just ask and I'll clear things up for you. Thanks, Rifle

Share this post


Link to post
Share on other sites
The Tree View item is a System.Windows.Controls.TreeView (the one gan referred me to was a System.Windows.Forms.TreeView item) and as for the first question, I believe it's VB NET, I'm not entirely sure. I'm using Microsoft Visual Basic 2008 Express Edition, if that says anything (normally I use C++ so for this project I decided to learn VB, so I'm kind of new to it and I'm learning as I go).

Share this post


Link to post
Share on other sites
Alright, I just looked and (apparently) what I'm using for the main window isn't a Windows Form, its a WPF Window (or Windows Presentation Foundation Window). However, I don't want to redo my whole window (especially because I really like how it looks) so I'm thinking maybe I could set a property of a TreeView control called ItemSource in the XAML code for the window and maybe set that value to a container containing all my TreeViewItems. I'm not sure if this will work yet though. But I know nothing about any of this (yet) so if you know how to do that please tell me but if I find out how before anyone posts anything then I'll let you know if it worked or not.

By the way, if any of you are wondering what it is that I'm making:
Here's the home page for my website:
riflegamedevelopment.web.officelive.com

And here's a link to the page for my application:
riflegamedevelopment.web.officelive.com/weaponLibrary.aspx

Share this post


Link to post
Share on other sites
Oook, I have FINALLY figured out how to create items to the TreeView control via code, and I found it because I accidentally hit the 'A' key on my keyboard, no less. I was setting the ItemsSource property to a class I created that inherited the ObservableCollection(Of T) class but that didn't work so I typed (and the TreeView control is named "weaponProfiles") "weaponProfiles.Items.A and the autocomplete came up with an "Add". So, I messed with that and all you have to write - assuming that exampleOne is a TreeViewItem object - is "weaponProfiles.Items.Add(exampleOne)" and that's it. So that problem is solved in case anyone needs to do that (such as myself). Now hopefully I can find a way to make it work for my application.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this