TreeView Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • EdB

    #1

    TreeView Help

    I am having trouble selecting a node on a tree control. The code below is
    returning me the proper index, of that I'm sure. The SelectedNode statement
    returns the error Object Reference Not Set To An Object. While I'm asking, I
    want to not only select the node but ensure that it is visible. In other
    words, I have a tree control that displays 10 entries, but the control actual
    contains thirty. Maybe the one I am trying to programmaticall y select can
    not currently be seen without moving the scroll bar. I want it to select the
    right node, and make sure that the scroll bar position has it displayed. Any
    help is appreciated.

    Dim sKey As String
    For Each sKey In hTreeKey.Keys
    Dim l As Long = CLng(hTreeKey.I tem(CInt(sKey)) )
    If l = CLng(objPin.Nam e) Then
    Dim t As TreeNode = treeBuiltRoutes .Nodes.Item(CIn t(sKey))
    treeBuiltRoutes .SelectedNode = t
    Exit For
    End If
    Next
  • Cor Ligthert [MVP]

    #2
    Re: TreeView Help

    Ed,

    The problem with things as treeview is that by instance a selected event is
    fired, when you set that in your program. This means by instance if you do
    that in your selected change event that you have quick unwanted recursion.
    (Endless looping from the same event untill the stack or memory is full or
    sometimes unexpected error answers).

    (I have seen that you select a node in your code, however cannot see where
    that is)

    I hope this gives an idea.

    Cor


    Comment

    • EdB

      #3
      Re: TreeView Help

      Cor,

      I don't really know what you are saying there, but here's a more
      straightforward question.

      The documentation says that the SelectedNode property "Gets or sets the
      treenode that is currently selected in the treeview control".

      The only example I can find is the "Get" portion. I can not find an example
      of "set", nor can I get it to work.

      Ed

      "Cor Ligthert [MVP]" wrote:
      [color=blue]
      > Ed,
      >
      > The problem with things as treeview is that by instance a selected event is
      > fired, when you set that in your program. This means by instance if you do
      > that in your selected change event that you have quick unwanted recursion.
      > (Endless looping from the same event untill the stack or memory is full or
      > sometimes unexpected error answers).
      >
      > (I have seen that you select a node in your code, however cannot see where
      > that is)
      >
      > I hope this gives an idea.
      >
      > Cor
      >
      >
      >[/color]

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: TreeView Help

        Edb,

        What I am saying with a simple pseudo code sample is

        Sub DoEvent as EventChange
        MyEvent += 1
        End sub

        This routine stops as the memory is full (or another reason) and is
        something I have seen in your code.

        However we don't know where you have placed that code, I must be a sub or a
        function. However, what subroutine or function, do you leave as a complete
        mystery for us, while that is important by setting the selected node.

        I hope this helps,

        Cor


        Comment

        Working...