• 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

    • I've written a Substack article where I talk about the expected release date for Debian 13 (August 9th) and cover some of the upcoming changes that will either affect me personally, or that I thought noteworthy.  You can read the whole thing here: https://open.substack.com/pub/gerowen/p/debian-gnulinux-13-trixie-is-just?r=54rcsd&utm_campaign=post&utm_medium=web&showWelcomeOnShare=true It's rather long and has several images that would probably exceed the attachment limit, but I'll copy and paste the first little bit of it here:  
    • Too many middle managers at these big companies are the problem imo. The guys under them do all the work but these VPs or PMs fight with each other in order to move up the ladder which just messes things up.
    • Microsoft lifts another long-standing Windows 11 24H2 block, allowing more people to upgrade by Taras Buria In October 2024, Microsoft released Windows 11 version 24H2 with quite a long list of known bugs and upgrade blocks. Ever since, Microsoft has been slowly patching those bugs and lifting blocks one by one. Now, the company is removing another upgrade block, letting more Windows 10 and Windows 11 users upgrade to the latest version ahead of the upcoming end of Windows 10 support. The block in question affects PCs with Easy Anti-Cheat, an anti-cheat solution embedded in many popular games, such as PUBG or Fortnite. According to the official documentation, the compatibility issue affects systems with Intel's Alder Lake+ processors and the vPro platform with Easy Anti-Cheat drivers released before April 2024. Affected systems crash to the blue screen of death (now black screen of death) with the "MEMORY_MANAGEMENT" error. However, blue screens of death do not occur if games do not use outdated drivers that are present on the device. The upgrade block was placed on September 30, 2024, and now, nearly ten months later, Microsoft has lifted it. As of July 24, 2025, affected systems can finally install Windows 11 version 24H2 via Windows Update. Note that Windows Update might still prompt you to update games that use an incompatible Easy Anti-Cheat version. Compatibility issues with Easy Anti-Cheat are only present in Windows 11 version 24H2, so if you are running older Windows 11 versions or Windows 10, there should not be any crashes, even with outdated drivers. Windows 11 version 25H2 is coming in a couple of months, but its predecessor still has several upgrade blocks in place. There are compatibility issues with Intel Smart Sound Technology drivers, hanging apps that use the camera, audio output losses on PCs with Dirac Audio, and sprotect.sys driver issues.
    • XRECODE3 1.169 by Razvan Serea xrecode3 is a converter and audio-grabber which allows you to convert from mp3, mp2, wma, aiff, amr, ogg, flac, ape, cue, ac3, wv, mpc, mid, cue ,tta, tak, wav, wav(rf64), dts, m4a, m4b, mp4, ra, rm, aac, avi, mpg, vob, mkv, mka, flv, swf, mov, ofr, wmv, divx, m4v, spx, 3gp, 3g2, m2v, m4v, ts, m2ts, adts, shn, tak, xm, mod, s3m, it, mtm, umx, mlp to m4a, alac, ape, flac, mp3, mp4 (using NeroAAC), ogg, raw, wav, wav(rf64), wma, WavPack, mpc, mp2, Speex, ofr, ac3, aiff, tak, snd and Shorten formats. Command Line parameters are supported. XRECODE3 features: Works on XP, Vista, Windows 7, Windows 8, 10 32/64 bit versions and under Wine. Parallel conversion by utilizing power of multi-core CPUs. Support of embedded CUE sheets (for FLAC, WavPack, APE and TAK files). Support of mp4, mka chapters (can split mp4, mka by chapters to any supported format). Built-in Metadata editor with Cover Art support. Has support for LossyWav. Supports portable mode. Merge input files to one large audio file and create CUE sheet. Converting to many formats at once using "Multiple" output mode. Grabbing of multi-channel Audio CDs to the desired format at once. Informative and resizable UI suited even for netbooks. Extracting audio from flv, avi, mov etc. video files (multiple audio streams are supported). Can export/import Metadata to/from external file. Support for 24/32bit audio files. Multilanguage support. Currently program is available in Dutch, English, French, Japanese, Korean, Polish, Russian, Hungarian, Italian, Spanish, Spanish Traditional, Swedish, Brazilian Portuguese, German, Finnish, Bulgarian, Czech, Danish and Chinese (simplified) languages. What's new in XRECODE3: Native 64bit support. Added support for DSD/DST and DFF formats (including handling of SACD ISOs). Added option to extract audio without transcoding. Added option to encode several files to one multi-channel file. Added option to split file into individual track-per-channel for all available output formats. Added option to merge files per folder. Output and Metadata settings are now output format specific. Enhanced Metadata settings. Added support for multiple Cover pictures in Metadata editor. Added 32bit int/float output for formats which support them (e.g. WAV). Added dithering option in Output Settings. Added option to use EBUR128 in Normalize. Added option to Album Mode Normalize. Added option to configure Matrices under Output Settings. Added more output file pattern elements. Tabbed UI. CUE files are now displayed more nicely. Enhanced Shell Extension. XRECODE3 1.169 changelog: FIX: resolved an issue where playlist file names was created with 2 dots before the file extension. FIX: fixed issue with encoding some files to ac3 format. Download: XRECODE3 v1.169 (64-bit) | Portable | ~30.0 MB (Shareware) Download: XRECODE3 v1.169 (32-bit) | Portable Link: XRECODE3 Homepage | XRECODE3 Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • So... Tesla fails, SpaceX fails, not Starlink... I guess karma is a bitch...
  • Recent Achievements

    • Week One Done
      Itbob513626 earned a badge
      Week One Done
    • One Month Later
      Itbob513626 earned a badge
      One Month Later
    • Rookie
      EdwardFranciscoVilla went up a rank
      Rookie
    • Week One Done
      MoJo624 earned a badge
      Week One Done
    • Collaborator
      aeganwn earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      619
    2. 2
      ATLien_0
      242
    3. 3
      Xenon
      160
    4. 4
      Michael Scrip
      123
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!