|
-
Jan 1st, 2003, 05:33 PM
#1
Thread Starter
Hyperactive Member
Treeview Questions
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?
-
Jan 1st, 2003, 06:03 PM
#2
Sleep mode
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)
-
Jan 1st, 2003, 06:19 PM
#3
Thread Starter
Hyperactive Member
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:
VB Code:
if user has selected this node then
do this
end if
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.
I think it's time to start revising Treeview's pirate
-
Jan 1st, 2003, 07:00 PM
#4
Sleep mode
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
-
Jan 2nd, 2003, 08:21 AM
#5
Thread Starter
Hyperactive Member
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?
-
Jan 3rd, 2003, 09:57 AM
#6
Junior Member
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())
-
Jan 3rd, 2003, 04:26 PM
#7
Sleep mode
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
-
Jan 4th, 2003, 05:28 AM
#8
Thread Starter
Hyperactive Member
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
Last edited by RealNickyDude; Jan 4th, 2003 at 05:56 AM.
-
Jan 4th, 2003, 11:45 AM
#9
Thread Starter
Hyperactive Member
Anyone help? I can't continue with the VBCodebook .NET otherwise
-
Jan 6th, 2003, 04:21 AM
#10
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|