• 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

    • Both a game adaptation and it's on Amazon I'll set my hopes low
    • You shut your mouth you young fart, that was just a few years ago, lol.
    • Good effort, but unfortunately not very useful in the real world, since it doesn't support UEFI - which is a major drawback. More than that, most PCs these days have Secure Boot enabled by default, so unless you're tech savvy, the average joe is not going to disable Secure Boot - which means automated Windows > Linux migration programs like this will not work. And if you're tech savvy enough to know how to disable Secure Boot, then you're tech savvy enough to just flash a USB drive and install Linux the usual way - after all, the actual installation process is just point-and-click. So I don't see a use case here to be honest, especially considering the lack of UEFI support - especially when you consider that more and more Linux distros are completely dropping BIOS support (eg Fedora dropped it back in 2022). So this program is a bit too late to the party.
    • I agree with open rights group that the age check companies should be regulated but action does need to be taken imo, they may be called irresponsible parents but the fact is that many don't know how to set up blocks. Why should kids suffer because their parents don't know something? I think the UK has always been a bit like this. We don't say healthcare is your responsibility, we tax everyone and make people register with the NHS. We also don't expect everyone to brush their teeth to maintain dental health, we just put fluoride in their water assuming people aren't brushing enough, because some probably aren't or aren't doing it properly. In general, this way of doing things works.
  • Recent Achievements

    • One Month Later
      Falcon.ai earned a badge
      One Month Later
    • Week One Done
      Falcon.ai earned a badge
      Week One Done
    • Dedicated
      EYEREX earned a badge
      Dedicated
    • First Post
      Electronic Person earned a badge
      First Post
    • Week One Done
      CyberCeps666 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      630
    2. 2
      ATLien_0
      237
    3. 3
      Xenon
      165
    4. 4
      neufuse
      142
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!