• 0

[vb.net] treeview and listview controls


Question

i'm trying to use the treeview and listview controls similar to how they would look in something like explorer. i would have nodes in the treeview that would change what was shown in the listview. i am pretty fluent in vb.net (not as much as some of you, i'm sure), but i've never used these controls before. i think i have got down adding new nodes to the treeview, but i'll have to play with it for a while. also, i need to find out how to delete/remove a node and all its subnodes, but i should be able to figure this out from MSDN.

if possible, i'd also like to know how to modify the contents of these via a context menu (like explorer). ie. rename, delete, new folder/node, etc. how can i have the treeview take what the user types as a new name when they select "rename" from the context menu, etc?

Link to comment
https://www.neowin.net/forum/topic/112450-vbnet-treeview-and-listview-controls/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

add node: treeview.items.add "text"

remove: treeview.items.remove(index of node you wish to remove)

rename node: treeview.items(index of node).text = "new text"

its pretty much the same for the treeview

to add a treeview item with an image however, assign an imagelist to it, and in the parameters of the .add function, you can specify which icon index to use for the picture

  • 0

i've figured out how to delete a node, so that works fine. i also discovered the user can rename a node by clicking on the selected node. this will work... but it's not what i want. i'd like to know how to programatically "click" the selected node so the user can type a different name for it.

also, how can i highlight a node of my choice? :blink: this is my code to add a subnode to the selected node. the last line is supposed tho highlight the newly created node. i swear should work, but it doesn't :huh:

  VB.NET said:
Dim temp As New TreeNode()

Dim parentNode As TreeNode

parentNode = TreeView1.SelectedNode

temp.Text = "New subnode"

parentNode.Nodes.Add(temp.Text) ? ?'add the subnode to the selected parent node

parentNode.Expand() ? ? ?? ? ? ? ?? ? ? ?? 'expand parent node, so new subnode is visible

TreeView1.SelectedNode = temp ? ?? ?'this SHOULD highlight/select the new subnode i just created two lines ago

edit: colo:cool:d code rules :cool:

Edited by gameguy
  • 0

This isn't totally on-topic, but I should make a VB.NET code colorizer that converts VB.NET code into IPB colorized code. :)

I might make my own little app like that. :) gameguy, do you know the API to get the icon for an EXE, and the icon for a file association?

  • 0

memodude: sorry, i don't know anything about getting an icon from an exe :/ all i know how to do is use reshacker to extract them :whistle:

winston: what do you mean "add code" to a node? :blink: i figured out how to add and delete a node (and i could probably change the order if i wanted...) but what are you wanting to do?

now that i have the treeview done, i need to make a context menu (right click menu, for when the user right clicks a node) and work on the listview control. i tried playing around with the context menu, but it doesn't like me or something, so i'll put that aside for now :happy:

  • 0

Try adding a

TreeView1.Select

after TreeView1.SelectedNode = temp so that the treeview becomes the active control.

and then add

newNode.BeginEdit()

If you want the users to rename on adding the new node.

Make sure the treeview has the LabelEdit property set to true.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • They've been focusing on security and quality? Could have fooled me. Their own paying customers literally just got breached because they failed to push SharePoint updates downstream to on prem servers operating outside of their "365" ecosystem.
    • The animosity is unnecessary, when I opened the page I only saw one response which never mentioned your other steps, and when I hit reply it jumped straight to the bottom and again, I saw no other responses.  I was simply agreeing with the first comment that said yes, you should be fine if you erase its current operating system. Using another PC, or the copy of Windows that comes on that PC (former option is more trustworthy), download and run the Windows Media Creation tool.  It will walk you thru the process of downloading Windows and writing it to a USB stick.  It will even ask you at one point whether you're reinstalling it to the current machine or installing it on another machine. Then just boot the PC in question from that USB stick.  Usually spamming Esc, Del, F-8, F-9, F-10, F-11, F-12 or F-2 immediately after power on will bring up a boot menu, it varies by manufacturer.  If Windows starts booting you either missed your window or hit the wrong key. Follow the on-screen instructions.  When it gets to the disk formatting part I usually just delete all the partitions on the destination drive, then select the unpartitioned space as my destination.  The Windows installer will then automatically partition the drive as needed. Be prepared to download drivers from the PC manufacturer's website, they may not come bundled with Windows and you may not be able to use things like WiFi or ethernet until you have them.  They "might" work straight away, but they also might not.  Better to be prepared with a spare PC and a USB stick to transfer them over.
    • Wise Disk Cleaner 11.2.5 by Razvan Serea Wise Disk Cleaner is a free disk utility designed to help you keep your disk clean by deleting any unnecessary files. Usually, these unnecessary, or junk files appear as a result of program's incomplete uninstalls, or Temporary Internet Files. It is best if these files are wiped out from time to time, since they may, at some point, use a considerable amount of space on your drives. Wise Disk Cleaner, with its intuitive and easy to use interface, helps you quickly wipe out all the junk files. Using the program is indeed easy. It also works fast when both scanning for files and deleting files. The new Wise Disk Cleaner has more advantages: improved performance, better interface and scans/cleans more thoroughly. Wise Disk Cleaner Free provides lifetime free update service and Unlimited Free technical support. The first Slimming System software Wise Disk Cleaner is the first system slimming tool, which will help you to remove Windows useless files that you don't need, such as Korean IME, Windows Sample music, videos, pictures, Installers and Uninstallers of Updates Patches etc. Wise Disk Cleaner 11.2.5 Build 845 changelog: Added cleaning rules for Legacy Games Launcher, Letasoft Sound Booster, Macrium Reflect, MagicLine4NX, MAGIX Photostory, MakeHuman, Max Recorder, Maxprog iCash, Lexware, LG PC Suite, Lightworks, LINE, Listary, and LockHunter. Improved cleaning rules for Xunlei, PowerToys, Meitu, OneDrive, and Tencent Video. For security reasons, users can no longer delete the latest system restore point in the Restore Center. Enhanced System Slimming. Fixed minor bugs from the previous version. Download: Wise Disk Cleaner 11.2.5 | 6.9 MB (Freeware) Download: Portable Wise Disk Cleaner 11.2.5 | 7.3 MB View: Wise Disk Cleaner Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I keep getting ignored when I ask what you guys mean by nuke it. I described the steps and I keep getting the same generic instructions. Can you look at what I have posted multiple times already and validate what I have described? You can't assume everyone has your level of expertise and can interpret your nuking advice. After this many posts in this thread, I don't think we need the same generic advice about just nuke it and reinstall. It's already been said. So can you please outline the specifics? Made in Ukraine? Are you sure?
  • Recent Achievements

    • One Year In
      armandointerior640 earned a badge
      One Year In
    • One Month Later
      armandointerior640 earned a badge
      One Month Later
    • One Month Later
      Itbob513626 earned a badge
      One Month Later
    • Week One Done
      Itbob513626 earned a badge
      Week One Done
    • Rookie
      EdwardFranciscoVilla went up a rank
      Rookie
  • Popular Contributors

    1. 1
      +primortal
      615
    2. 2
      ATLien_0
      236
    3. 3
      Xenon
      155
    4. 4
      +FloatingFatMan
      120
    5. 5
      Michael Scrip
      115
  • Tell a friend

    Love Neowin? Tell a friend!