Trouble with Treeview Nodes
Trouble with Treeview Nodes
Trouble with Treeview Nodes
Trouble with Treeview Nodes
Trouble with Treeview Nodes
Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes
Trouble with Treeview Nodes Trouble with Treeview Nodes
Trouble with Treeview Nodes
Go Back  Xtreme Visual Basic Talk > > > Trouble with Treeview Nodes


Reply
 
Thread Tools Display Modes
  #1  
Old 09-11-2014, 11:20 AM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default Trouble with Treeview Nodes


For now, that is only a practice app that i am
messing with but only until i can get the hang
of using a treeview.

First off, i have the treeview connected to a imagelist.

I can add the root node just fine but when i go to add
a child node under the root, the treeview collapses and
i can't stop it, now matter what i do.

When i add another parent node to the treeview, all the
nodes collaspe and also all the images change to a folder
image.

So the layout of the nodes would look something like this.

***Edit***
The treeview layout didn't come out right. I'll try it in a code box

Code:
RootNode          ' Folder image for parent nodes
       ChildNode  ' Green box for child nodes
ParentNode       ' Folder image
***End Edit***

After looking at that myself, there should be no nodes
below the root node. Am i correct? Should the ParentNode
be under the ChildNode?

Another problem that arises is that the treeview has a
selectedImageIndex that works off of the Imagelist.

Every time i click on a folder node, it changes to a green
box image and the green box changes to a folder image.
I don't think there is a fix for that last problem, unless i
just don't use the imagelist or create a custom imagelist
without the selectedImageIndex property.


***Edit**********************************
Ooooopppsss
Meant to say Treeview. Long night last night. LOL
****************************************

Anyway, any help would be appreciated. I've been looking
around online for fixes for these problems but nothing that
i have found is working.

Last edited by VB_Alien; 09-12-2014 at 10:55 AM.
Reply With Quote
  #2  
Old 09-11-2014, 12:46 PM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

Here's the code that i'm using right now

Code:
Dim node As TreeNode

Private Sub Form_Load()
   ' This doesn't work
   node.SelectedImageIndex = -1
End Sub

Private Sub NewProject()
   ' The root node
   node = TV1.Nodes.Add(TextBox1.Text)
End Sub

Private Sub NewMap()
   ' Child node under root
   node.ImageIndex = 1
   node.Nodes.Add(frmAddMap.TextBox1.Text)
   node.ExpandAll()
End Sub

Private Sub NewFolder()
   node.ImageIndex = 0
   node = TV1.Nodes.Add(frmNewFolder.TextBox1.Text)
   node.ExpandAll()
End Sub

Using the ExpandAll property of the treeview, i can
keep the nodes expanded right now. Problem solved.

Still having issues with the images in the treeview though.

I can load in the root folder and image fine.
I can load in map folders and images fine.

When i go to add another folder though, all the images
change to folder images.

Still having issues with the selected image property to.
I don't want the images changing on the nodes, every time
i click on one.
Reply With Quote
  #3  
Old 09-11-2014, 03:01 PM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

I guess one of my problems was that i was
using as node variable to get treeview nodes
but by doing that, it doesn't have a selectednode
property and that was throwing me off. I went
back to using the treeview.selectednode property
and now i'm adding root and child nodes pretty good.

I'm still having trouble with that imagelist control
though. I found a sub online that checked for child
nodes and i modified it a little and turn it into a
function.

If child found then
I set both indexes to 1 - the green folder
e.Node.ImageIndex = 1
e.Node.SelectedImageIndex = 1
else
I set both of them to 0 - yellow folder
e.Node.ImageIndex = 0
e.Node.SelectedImageIndex = 0

This works sometimes and sometimes it don't and
i have to click on child nodes to get them to show the
green solder again.

That imagelist is really fighting to gain control of the
image property that i set for each node.

Is there a way to load images into a node without using
the imagelist?

I'm going to experiment with my resources in the mean time
to see what i can find.
e.Node.SelectedImageIndex = 1
Reply With Quote
  #4  
Old 09-12-2014, 11:05 AM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

Stilling having the same issue. I even created a new
treeview class ans inherited the treeview control.

Then i created overloaded properties of the SelectedImageIndex
and SelectedImageKey and set their browsing attributes to false
in the properties designer and the editor.

Still doing the same thing.

Clicking on nodes, changes the node image to a different image.

I never had this problem before and i'm not sure what to do.
Reply With Quote
  #5  
Old 09-12-2014, 05:22 PM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

Didn't even get a nibble. Everyone must be on there surfboards today.

Oh well. Makes me work, just that much harder.

I've been fighting this image changing in the nodes for 2 days
and no one online even had a fix for this.

I used the imagekey number and the selectedimagekey string value
and was having no luck at all for 2 days.

Today, i found a site where the person was creating a new instance of
the imagelist control in memory and just using that along with using
the imagekey and selectedimagekey properties of the treeview and
that worked real well for me.

Now i'm setting the nodes like i did back in the vb6 days and it works
so much better. Could not use the index numbers PERIOD! To messy.

Anyway, i'll post what i found, in case someone else has this problem.

Under Class Form1
Private ImageList1 As ImageList = New ImageList


In the form_load i create the imagelist and populate it with 2 images
Then i create the first root node.
Code:
 ImageList1.ImageSize = New Size(16, 16)

        ' Load images into imagelist
        ImageList1.Images.Add("Folder", Image.FromFile(Application.StartupPath & "\Graphics\Folder1.png"))
        ImageList1.Images.Add("Marker1", Image.FromFile(Application.StartupPath & "\Graphics\Marker1.png"))

        ' Connect imagelist to treeview
        TV1.ImageList = ImageList1

        ' Using imagelist key instead of index number

        'Creating the root node
        TV1.Nodes.Add("Project 1", "Project 1", "Folder1", "Folder1")
Then i have 2 subs creating the other nodes
Code:
Private Sub AddParent()
      ' IN RED    Node Key - Node Text - ImageIndex - SelectedImageIndex
      TV1.Nodes.Add("Project 2", "Project 2", "Folder1", "Folder1")
      TV1.ExpandAll()
End Sub

Private Sub AddChild()
      ' IN RED    Node Key - Node Text - ImageIndex - SelectedImageIndex
      TV1.SelectedNode.Nodes.Add("Map1", "Map1", "Marker1", "Marker1")
      TV1.ExpandAll()
End Sub
Well. Now that that problem is solved, on the the next one.

This forum isn't parsing code right. It's leaving out at least one
comma and one word with quotations is completely missing.

I've tried to edit it but it comes back out the same as before.

I'll just upload the code.
Attached Files
File Type: zip TreeViewDemo.zip (53.6 KB, 0 views)

Last edited by VB_Alien; 09-12-2014 at 05:55 PM. Reason: Forum not parsing code correctly
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Trouble with Treeview Nodes
Trouble with Treeview Nodes
Trouble with Treeview Nodes Trouble with Treeview Nodes
Trouble with Treeview Nodes
Trouble with Treeview Nodes
Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes Trouble with Treeview Nodes
Trouble with Treeview Nodes
Trouble with Treeview Nodes
 
Trouble with Treeview Nodes
Trouble with Treeview Nodes
 
-->