I have a treeview and i wish to see which node the user's selected. I know you can use e.node.text but the text can be subject to change so is there any other way to check, like using the tag? How do I set the tag for each indvidual node?
Printable View
I have a treeview and i wish to see which node the user's selected. I know you can use e.node.text but the text can be subject to change so is there any other way to check, like using the tag? How do I set the tag for each indvidual node?
VB Code:
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object _ , ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect MsgBox(TreeView1.SelectedNode().ToString) End Sub
this way no matter the node caption is , try to figure it out !
(I've never worked with Treeview since 2 years):D
It does work, but it returns the text of the node, like e.node.text. I have text like "Save or append text to a file" and i want something like:
but I don't want to check for "Save or append text to a file" as this text could change, i want to check for something simple like the tag property, something like f1 or f2 for File Handling, or vfx1 or vfx2 for Visual FX, as these wouldn't change.VB Code:
if user has selected this node then do this end if
I think it's time to start revising Treeview's pirate :D
try this
VB Code:
Dim treev As New TreeNode() Dim i As Integer Private Sub TreeView1_AfterSelect(ByVal sender As System.Object _ , ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect Select Case e.Node.Index = i Case i = 0 MsgBox("index 0 ") Case i = 1 MsgBox("index 1") Case i = 2 'do the next End Select End Sub
Thanks again pirate, but.... (sorry) If i insert extra nodes then that will throw the index numbers out, I know there is a tag property but how do i set the tags for individual nodes?
I don't know if this is what you want.VB Code:
' Assume your treeview control is called TreeView1. ' This bit of code goes in the Form_Load function. TreeView1.Nodes.Add("Node 1") TreeView1.Nodes.Add("Node 2") TreeView1.Nodes.Add("Node 3") TreeView1.Nodes(0).Tag = "mynode1" TreeView1.Nodes(1).Tag = "mynode2" TreeView1.Nodes(3).Tag = "mynode3" ' And this goes in the TreeView1_AfterSelect function. MessageBox.Show("You selected " & TreeView.SelectedNode.Tag())
the first three lines will generate three nodes at runtime , so you could left them out and everything will goes fine.
nice try by the way
Thanks, i'll try that.
Another Treeview question:
I want my program to create a Treeview by reading a directory, any directories in that, and then any files inside those directories.
Basically, I'd like to program to create it's own treeview. The Main Directory is set (it's called Code) but then i'd like to program to look inside the Code directory and make a treeview of what's in there.
This is way above my head but there might be a kind soul out there :)
Anyone help? I can't continue with the VBCodebook .NET otherwise :(
Anyone?