Avatar of jantrey
jantrey

asked on 

Newbie question regarding treeview and listview

I am new to programming learning about VB.NET.

I have a treeview which I added nodes in the TreeNode Editor. I would like to show the "child nodes" in Listview when I click on a node in treeview (like windows explorer). I saw many tutorials but I do not understand them. What is the EASIEST way to do this?
.NET Programming

Avatar of undefined
Last Comment
krinpit
Avatar of Mikal613
Mikal613
Flag of United States of America image

when you click the treeview you cann just add the the text of the nodes to the Listview

OnCLick of the treeview
    Listview1.Add treeview nodes
Avatar of Mikal613
Mikal613
Flag of United States of America image

You may have to register but its worth it
ASKER CERTIFIED SOLUTION
Avatar of EBatista
EBatista

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of jantrey
jantrey

ASKER

That's exactly what I needed!!!! Can I ask then...how do I add icons to the listview?
Avatar of EBatista
EBatista

well the better way to do that is dragging an ImageList control from the toolbar to the Form, then select the new added imagelist control and in the property windows fill its Images property which is a collection of images, once you have done so, select the ListView control and in the property windows set its SmallImageList and LargeImageList properties to the ImageList control added in the previous step (also you can have two ImageList control, one for each property). Then you can modify the event handler:

Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        Dim theItem As ListViewItem
        Dim oNode As TreeNode

        For Each oNode In TreeView1.SelectedNode.Nodes

            theItem = New ListViewItem(oNode.Text)
            theItem.ImageIndex = 0 'HERE setting the first image
            Me.ListView1.Items.Add(theItem)
        Next
End Sub


regards

Avatar of jantrey
jantrey

ASKER

Thank you very much!!
Avatar of krinpit
krinpit

Jantrey,

If you are going to develop this further, I suspect that eventually you will need a method of getting the system-default icon for each item.
This link explains everything, step by step:
http://www.codeguru.com/vb/gen/vb_misc/icons/article.php/c5597/
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo