+ Reply to Thread
Results 1 to 6 of 6

treeview node tag hold array?

  1. #1
    RB Smissaert
    Guest

    treeview node tag hold array?

    Trying to find a better way to let a treeview hold data and thought that
    perhaps the Tag of the treeview nodes
    could hold arrays, so I tried this.

    In one Sub:

    dim arr(1 to 2, 1 to 35)

    Set nodx = _
    MainForm.TreeView1.Nodes.Add(actNodeKey, tvwChild, , , Image:=3)

    nodx.tag = arr

    Then in another Sub:

    ..TreeView1.SelectedItem.Tag(1, 8) = "test"

    But when I run this for the first time I get an out of stack space error and
    the second time Excel just unloads, so a crash.

    Couldn't find anything about how this could be done, but if it could work it
    would be better
    than the way I do this now, which is hold the node data in an array and
    update the array according
    to what happens to the nodes.
    Thanks for any advice.


    RBS


  2. #2
    keepITcool
    Guest

    Re: treeview node tag hold array?



    yeah.. strange.
    probably due to passing the node byval

    Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    With Node
    If IsArray(.Tag) Then
    'this works
    Dim v
    v = .Tag
    v(UBound(v, 1), UBound(v, 2)) = "indirect"
    .Tag = v
    'this fails
    .Tag(UBound(.Tag, 1), UBound(.Tag, 2)) = "direct"
    MsgBox .Tag(UBound(.Tag, 1), UBound(.Tag, 2))
    End If
    End With
    End Sub

    Private Sub UserForm_Initialize()
    Dim arr(1 To 10, 1 To 35) As String
    With TreeView1
    With .Nodes
    With .Add(, tvwChild, "key1", "text1")
    .Tag = arr
    End With
    End With
    End With
    End Sub



    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    RB Smissaert wrote :

    > Trying to find a better way to let a treeview hold data and thought
    > that perhaps the Tag of the treeview nodes could hold arrays, so I
    > tried this.
    >
    > In one Sub:
    >
    > dim arr(1 to 2, 1 to 35)
    >
    > Set nodx = _
    > MainForm.TreeView1.Nodes.Add(actNodeKey, tvwChild, , , Image:=3)
    >
    > nodx.tag = arr
    >
    > Then in another Sub:
    >
    > .TreeView1.SelectedItem.Tag(1, 8) = "test"
    >
    > But when I run this for the first time I get an out of stack space
    > error and the second time Excel just unloads, so a crash.
    >
    > Couldn't find anything about how this could be done, but if it could
    > work it would be better than the way I do this now, which is hold the
    > node data in an array and update the array according to what happens
    > to the nodes. Thanks for any advice.
    >
    >
    > RBS


  3. #3
    RB Smissaert
    Guest

    Re: treeview node tag hold array?

    KeepITCool,

    > 'this works
    > Dim v
    > v = .Tag
    > v(UBound(v, 1), UBound(v, 2)) = "indirect"
    > .Tag = v


    Thanks for that, that works indeed!
    Just wonder how you came up with that.
    If I can implement this fully it will simplify a lot of things.
    For example deleting or inserting nodes could be done without complex
    array manipulations.
    It would be a reasonably big re-write of my app, but I think it would be
    worth it on the long run.

    RBS


    "keepITcool" <[email protected]> wrote in message
    news:[email protected]...
    >
    >
    > yeah.. strange.
    > probably due to passing the node byval
    >
    > Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    > With Node
    > If IsArray(.Tag) Then
    > 'this works
    > Dim v
    > v = .Tag
    > v(UBound(v, 1), UBound(v, 2)) = "indirect"
    > .Tag = v
    > 'this fails
    > .Tag(UBound(.Tag, 1), UBound(.Tag, 2)) = "direct"
    > MsgBox .Tag(UBound(.Tag, 1), UBound(.Tag, 2))
    > End If
    > End With
    > End Sub
    >
    > Private Sub UserForm_Initialize()
    > Dim arr(1 To 10, 1 To 35) As String
    > With TreeView1
    > With .Nodes
    > With .Add(, tvwChild, "key1", "text1")
    > .Tag = arr
    > End With
    > End With
    > End With
    > End Sub
    >
    >
    >
    > --
    > keepITcool
    > | www.XLsupport.com | keepITcool chello nl | amsterdam
    >
    >
    > RB Smissaert wrote :
    >
    >> Trying to find a better way to let a treeview hold data and thought
    >> that perhaps the Tag of the treeview nodes could hold arrays, so I
    >> tried this.
    >>
    >> In one Sub:
    >>
    >> dim arr(1 to 2, 1 to 35)
    >>
    >> Set nodx = _
    >> MainForm.TreeView1.Nodes.Add(actNodeKey, tvwChild, , , Image:=3)
    >>
    >> nodx.tag = arr
    >>
    >> Then in another Sub:
    >>
    >> .TreeView1.SelectedItem.Tag(1, 8) = "test"
    >>
    >> But when I run this for the first time I get an out of stack space
    >> error and the second time Excel just unloads, so a crash.
    >>
    >> Couldn't find anything about how this could be done, but if it could
    >> work it would be better than the way I do this now, which is hold the
    >> node data in an array and update the array according to what happens
    >> to the nodes. Thanks for any advice.
    >>
    >>
    >> RBS



  4. #4
    keepITcool
    Guest

    Re: treeview node tag hold array?


    i'm not sure

    WHY do you need to hold an array per node?
    isn't that memory inefficient?

    I'd probably use the node's KEY.
    and keep my data in 1 big array.

    Use a dictionary for mapping "key" to
    array "position"




    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    RB Smissaert wrote :

    > KeepITCool,
    >
    > > 'this works
    > > Dim v
    > > v = .Tag
    > > v(UBound(v, 1), UBound(v, 2)) = "indirect"
    > > .Tag = v

    >
    > Thanks for that, that works indeed!
    > Just wonder how you came up with that.
    > If I can implement this fully it will simplify a lot of things.
    > For example deleting or inserting nodes could be done without complex
    > array manipulations.
    > It would be a reasonably big re-write of my app, but I think it would
    > be worth it on the long run.
    >
    > RBS
    >
    >
    > "keepITcool" <[email protected]> wrote in message
    > news:[email protected]...
    > >
    > >
    > > yeah.. strange.
    > > probably due to passing the node byval
    > >
    > > Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    > > With Node
    > > If IsArray(.Tag) Then
    > > 'this works
    > > Dim v
    > > v = .Tag
    > > v(UBound(v, 1), UBound(v, 2)) = "indirect"
    > > .Tag = v
    > > 'this fails
    > > .Tag(UBound(.Tag, 1), UBound(.Tag, 2)) = "direct"
    > > MsgBox .Tag(UBound(.Tag, 1), UBound(.Tag, 2))
    > > End If
    > > End With
    > > End Sub
    > >
    > > Private Sub UserForm_Initialize()
    > > Dim arr(1 To 10, 1 To 35) As String
    > > With TreeView1
    > > With .Nodes
    > > With .Add(, tvwChild, "key1", "text1")
    > > .Tag = arr
    > > End With
    > > End With
    > > End With
    > > End Sub
    > >
    > >
    > >
    > > --
    > > keepITcool
    > > > www.XLsupport.com | keepITcool chello nl | amsterdam

    > >
    > >
    > > RB Smissaert wrote :
    > >
    > >> Trying to find a better way to let a treeview hold data and thought
    > >> that perhaps the Tag of the treeview nodes could hold arrays, so I
    > >> tried this.
    > > >
    > >> In one Sub:
    > > >
    > >> dim arr(1 to 2, 1 to 35)
    > > >
    > >> Set nodx = _
    > >> MainForm.TreeView1.Nodes.Add(actNodeKey, tvwChild, , , Image:=3)
    > > >
    > >> nodx.tag = arr
    > > >
    > >> Then in another Sub:
    > > >
    > >> .TreeView1.SelectedItem.Tag(1, 8) = "test"
    > > >
    > >> But when I run this for the first time I get an out of stack space
    > >> error and the second time Excel just unloads, so a crash.
    > > >
    > >> Couldn't find anything about how this could be done, but if it

    > could >> work it would be better than the way I do this now, which is
    > hold the >> node data in an array and update the array according to
    > what happens >> to the nodes. Thanks for any advice.
    > > >
    > > >
    > >> RBS


  5. #5
    keepITcool
    Guest

    Re: treeview node tag hold array?

    Bart,

    else send me an example by email of
    what you'r trying to do exactly.

    email below. just add @ and .

    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    keepITcool wrote :

    >
    > i'm not sure
    >
    > WHY do you need to hold an array per node?
    > isn't that memory inefficient?
    >
    > I'd probably use the node's KEY.
    > and keep my data in 1 big array.
    >
    > Use a dictionary for mapping "key" to
    > array "position"


  6. #6
    RB Smissaert
    Guest

    Re: treeview node tag hold array?

    I don't think memory is an issue as these are not big treeviews and the
    arrays
    are only small.
    The beauty of this approach is that there always is a direct relation
    between
    the treeview node and the node data.
    For example delete node, automatically data gone as well, etc.
    So the gain will be simplicity and less code.
    I think I will give it a go.

    RBS


    "keepITcool" <[email protected]> wrote in message
    news:[email protected]...
    >
    > i'm not sure
    >
    > WHY do you need to hold an array per node?
    > isn't that memory inefficient?
    >
    > I'd probably use the node's KEY.
    > and keep my data in 1 big array.
    >
    > Use a dictionary for mapping "key" to
    > array "position"
    >
    >
    >
    >
    > --
    > keepITcool
    > | www.XLsupport.com | keepITcool chello nl | amsterdam
    >
    >
    > RB Smissaert wrote :
    >
    >> KeepITCool,
    >>
    >> > 'this works
    >> > Dim v
    >> > v = .Tag
    >> > v(UBound(v, 1), UBound(v, 2)) = "indirect"
    >> > .Tag = v

    >>
    >> Thanks for that, that works indeed!
    >> Just wonder how you came up with that.
    >> If I can implement this fully it will simplify a lot of things.
    >> For example deleting or inserting nodes could be done without complex
    >> array manipulations.
    >> It would be a reasonably big re-write of my app, but I think it would
    >> be worth it on the long run.
    >>
    >> RBS
    >>
    >>
    >> "keepITcool" <[email protected]> wrote in message
    >> news:[email protected]...
    >> >
    >> >
    >> > yeah.. strange.
    >> > probably due to passing the node byval
    >> >
    >> > Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    >> > With Node
    >> > If IsArray(.Tag) Then
    >> > 'this works
    >> > Dim v
    >> > v = .Tag
    >> > v(UBound(v, 1), UBound(v, 2)) = "indirect"
    >> > .Tag = v
    >> > 'this fails
    >> > .Tag(UBound(.Tag, 1), UBound(.Tag, 2)) = "direct"
    >> > MsgBox .Tag(UBound(.Tag, 1), UBound(.Tag, 2))
    >> > End If
    >> > End With
    >> > End Sub
    >> >
    >> > Private Sub UserForm_Initialize()
    >> > Dim arr(1 To 10, 1 To 35) As String
    >> > With TreeView1
    >> > With .Nodes
    >> > With .Add(, tvwChild, "key1", "text1")
    >> > .Tag = arr
    >> > End With
    >> > End With
    >> > End With
    >> > End Sub
    >> >
    >> >
    >> >
    >> > --
    >> > keepITcool
    >> > > www.XLsupport.com | keepITcool chello nl | amsterdam
    >> >
    >> >
    >> > RB Smissaert wrote :
    >> >
    >> >> Trying to find a better way to let a treeview hold data and thought
    >> >> that perhaps the Tag of the treeview nodes could hold arrays, so I
    >> >> tried this.
    >> > >
    >> >> In one Sub:
    >> > >
    >> >> dim arr(1 to 2, 1 to 35)
    >> > >
    >> >> Set nodx = _
    >> >> MainForm.TreeView1.Nodes.Add(actNodeKey, tvwChild, , , Image:=3)
    >> > >
    >> >> nodx.tag = arr
    >> > >
    >> >> Then in another Sub:
    >> > >
    >> >> .TreeView1.SelectedItem.Tag(1, 8) = "test"
    >> > >
    >> >> But when I run this for the first time I get an out of stack space
    >> >> error and the second time Excel just unloads, so a crash.
    >> > >
    >> >> Couldn't find anything about how this could be done, but if it

    >> could >> work it would be better than the way I do this now, which is
    >> hold the >> node data in an array and update the array according to
    >> what happens >> to the nodes. Thanks for any advice.
    >> > >
    >> > >
    >> >> RBS



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1