|
-
Nov 24th, 2007, 02:07 PM
#1
Thread Starter
Hyperactive Member
getting the right index of a child node.
Hi,
Im trying to use a treeview control to navigate through records on a different form, setting the position of the bindingsource on that form to the index of the selected node.
Now, the nodes I select are child nodes, so I need to get the index 5 if I select the first childnode under a parent and there are 4 other childnodes under different parents. As it is, I get index 1.
Do you know how I can solve this problem?
Fuga.
-
Nov 24th, 2007, 05:19 PM
#2
Re: getting the right index of a child node.
don't use the index.... try setting the key value and use tat.
-tg
-
Nov 25th, 2007, 04:13 AM
#3
Thread Starter
Hyperactive Member
Re: getting the right index of a child node.
Thanks for your reply.
The key value is set when you add the treenode, right? I can´t seem to access it. Here´s the code:
Code:
For Each tvrw In tvds.Tables(0).Rows
tvnode = New TreeNode
tvnode.Tag = tvrw.Item("Fid")
tvnode.Text = tvrw.Item("rubrik").ToString
tvnode.ToolTipText = tvrw.Item("info").ToString
Faktors.TreeView1.Nodes(0).Nodes.Add(tvnode)
If tvnode.Tag.ToString = Evaluate.TextBox7.Text Then
Faktors.TreeView1.SelectedNode = tvnode
End If
Next
I also tried using the name property but that didn´t work properly.
How do you think I should do it?
Thanks again.
Fuga.
-
Nov 25th, 2007, 04:18 AM
#4
Re: getting the right index of a child node.
I've done similar before using the .Tag of the node, then finding the node with the appropriate tag, so it doesnt matter when its shifted around.
But if you can get a key method working as recommended (which i wasnt aware of) that would save searching the nodes.
-
Nov 25th, 2007, 05:18 AM
#5
Thread Starter
Hyperactive Member
Re: getting the right index of a child node.
Thanks!
Yes I am using the tag, but for a different purpose.
The thing is, the posts are recorded in one way in the db, so I use the tag to find them there. But they are displayed in a different way in the form so I thought I should use the key for that.
I suppose I could use the tag and find the corresponding position in the bindingsource, move to that position etc, but I was hoping for a quicker way.
Fuga.
-
Nov 25th, 2007, 05:25 AM
#6
Re: getting the right index of a child node.
Well a tag is of type "Object" menaing you could put anything in there, like an array to hold 2 values.
But as for the key value, I found this msdn entry about it http://support.microsoft.com/kb/311318 it seems to explain it in depth
-
Nov 25th, 2007, 06:27 AM
#7
Thread Starter
Hyperactive Member
Re: getting the right index of a child node.
Thanks! That really helps a lot.
Well a tag is of type "Object" menaing you could put anything in there, like an array to hold 2 values.
Why is it that you always make a fool of yourself when you´re a beginner?
Great that I learned this, it´s going to help me in my project.
Fuga.
-
Nov 25th, 2007, 07:49 AM
#8
Thread Starter
Hyperactive Member
Re: getting the right index of a child node.
Hmm...
I´ve been trying to use the tag as an array, but I can´t get it to work.
I know how to declare the array and to assign values, but I don´t know how to turn the tag into an array.
I´m doing something wrong, aren´t I?
Fuga.
Visual Studio 2010 xpress, Visual Studio 2008 pro, SQL Server, SQL Server management studio 2008 r2, MSAccess
-
Nov 28th, 2007, 12:34 PM
#9
Thread Starter
Hyperactive Member
Re: getting the right index of a child node.
I've seen other people bump, so I try it too.
I haven´t been able to figure out how to assign an array to the tag property of a treenode. Can´t find it at msdn either.
Any help will be very appreciated.
Fuga.
Visual Studio 2010 xpress, Visual Studio 2008 pro, SQL Server, SQL Server management studio 2008 r2, MSAccess
-
Nov 29th, 2007, 06:50 AM
#10
Re: getting the right index of a child node.
Hi again,
I thought you were going to use the keys solution from msdn?
Anwyay, a Tag is a type "Object" so it can be ANYTHING, so theres no reason why it can't be an array, there's several ways to go about it.
here is the 1 liner way to make an array, test this for yourself (im just using a buttons tag)
Code:
Button1.Tag = New String() {"hi", "hello"}
MsgBox(Button1.Tag(0))
MsgBox(Button1.Tag(1))
a slower way, depending on your circumstances you may like better
Code:
Dim a As New List(Of String)
a.Add("hi")
a.Add("hello")
Button1.Tag = a.ToArray
Hope that helps.
-
Nov 30th, 2007, 10:37 AM
#11
Thread Starter
Hyperactive Member
Re: getting the right index of a child node.
Thanks Phill64!
No, once you told me that a tag could hold an array, I thought that would be a good way to go about it. I thought the key method looked more complex, and since I barely know what I´m doing half the time I thought I'll try the array stuff.
However, I think I´ve managed to put an array of values into the tag, but I´ve run into a different problem, which I posted in another thread.
http://www.vbforums.com/showthread.php?t=498811
Fuga.
Visual Studio 2010 xpress, Visual Studio 2008 pro, SQL Server, SQL Server management studio 2008 r2, MSAccess
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
|