Results 1 to 11 of 11

Thread: getting the right index of a child node.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Stockholm, Sweden
    Posts
    316

    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.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: getting the right index of a child node.

    don't use the index.... try setting the key value and use tat.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Stockholm, Sweden
    Posts
    316

    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.

  4. #4
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Stockholm, Sweden
    Posts
    316

    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.

  6. #6
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Stockholm, Sweden
    Posts
    316

    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.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Stockholm, Sweden
    Posts
    316

    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

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Stockholm, Sweden
    Posts
    316

    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

  10. #10
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Stockholm, Sweden
    Posts
    316

    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
  •  



Click Here to Expand Forum to Full Width