|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Baffeled by Treeview Nodes Index!!!!!collection but apparently I was wrong. I'm pretty sure the VB6 Treeview had unique node indexs but I don't want to set up an old computer with VB6 installed to check it. Please try the following tree structure and tell me if I'm nuts: Families ----Jones --------James ------------Frank ----Smith --------Willie ------------Bob ------------Lary ================== 1. Put a Treeview and a Listbox on a form. 2. Name the Treeview TV and paste the following code in the appropriate events 3. Click the tree nodes and observe the index of each. I understand that each node has its own nodes collection but is there a unique identifier for every node? If so, how do you get it. Without a unique index it seems to lead to some whacky results if you do the following: tv.Nodes.Remove(tv.SelectedNode) WHAT AM I MISSING? Thanks, Don Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim nod As TreeNode, wnod As TreeNode nod = tv.Nodes.Add("Families") nod = nod.Nodes.Add("Jones") nod = nod.Nodes.Add("James") nod = nod.Nodes.Add("Frank") nod.EnsureVisible() nod = tv.Nodes(0).Nodes.Add("Smith") wnod = nod.Nodes.Add("Willie") nod = wnod.Nodes.Add("Bob") nod = wnod.Nodes.Add("Larry") nod.EnsureVisible() nod = tv.Nodes(0).Nodes.Add("Johnson") nod.EnsureVisible() 'tv.HideSelection = False End Sub Private Sub tv_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tv.AfterSelect Dim n As TreeNode = tv.SelectedNode On Error Resume Next With ListBox1 .Items.Clear() .Items.Add("Index: " & n.Index.ToString) .Items.Add("Text: " & n.Text) .Items.Add("Kids: " & n.GetNodeCount(True)) .Items.Add("Parent: " & n.Parent.Index) End With End Sub
Show quote
Hide quote
"Don" <don81846@NO_CaCa.Earthlink.net> schrieb I didn't test the code, but if you need to identify a node, store a > > > I thought each Treeview node had a unique index in the nodes > collection but apparently I was wrong. > > I'm pretty sure the VB6 Treeview had unique node indexs but I don't > want to set up an old computer with VB6 installed to check it. > > Please try the following tree structure and tell me if I'm nuts: > > Families > ----Jones > --------James > ------------Frank > ----Smith > --------Willie > ------------Bob > ------------Lary > > ================== > 1. Put a Treeview and a Listbox on a form. > > 2. Name the Treeview TV and paste the following code in the > appropriate events > > 3. Click the tree nodes and observe the index of each. > > I understand that each node has its own nodes collection but is > there a unique identifier for every node? If so, how do you get it. > Without a unique index it seems to lead to some whacky results if > you do the following: > > tv.Nodes.Remove(tv.SelectedNode) > > WHAT AM I MISSING? > > Thanks, > > Don reference to the node. Armin In my example all nodes have an index of 0 except "Smith" and "Larry"
which each have an index of 1. Each sub tree seems to have its own 0 based indexing. The control must have been designed that way for some purpose. My question is . . . what purpose and how/when would I make use of it? I'm a long time VB programmer who's been away from it for quite a while and am trying to get my noggin around VB.Net. (I think this is try #3) This treeview thing is one of many that's befuddling me. I feel like one of those natives in the movies that see a cigarette lighter for the first time. Mundane if you're hip but magic if you're not. I'm, aparantly, not. :( Thanks, Don On Sat, 4 Mar 2006 02:55:45 +0100, "Armin Zingler" <az.nospam@freenet.de> wrote: Show quoteHide quote >"Don" <don81846@NO_CaCa.Earthlink.net> schrieb >> >> >> I thought each Treeview node had a unique index in the nodes >> collection but apparently I was wrong. >> >> I'm pretty sure the VB6 Treeview had unique node indexs but I don't >> want to set up an old computer with VB6 installed to check it. >> >> Please try the following tree structure and tell me if I'm nuts: >> >> Families >> ----Jones >> --------James >> ------------Frank >> ----Smith >> --------Willie >> ------------Bob >> ------------Lary >> >> ================== >> 1. Put a Treeview and a Listbox on a form. >> >> 2. Name the Treeview TV and paste the following code in the >> appropriate events >> >> 3. Click the tree nodes and observe the index of each. >> >> I understand that each node has its own nodes collection but is >> there a unique identifier for every node? If so, how do you get it. >> Without a unique index it seems to lead to some whacky results if >> you do the following: >> >> tv.Nodes.Remove(tv.SelectedNode) >> >> WHAT AM I MISSING? >> >> Thanks, >> >> Don > > >I didn't test the code, but if you need to identify a node, store a >reference to the node. > > >Armin "Don" <don81846@NO_CaCa.Earthlink.net> schrieb I should have tested it... I'm gonna do that now.> > In my example all nodes have an index of 0 except "Smith" and > "Larry" which each have an index of 1. Each sub tree seems to have > its own 0 based indexing. The control must have been designed that > way for some purpose. My question is . . . what purpose and how/when > would I make use of it? Armin
Show quote
Hide quote
"Don" <don81846@NO_CaCa.Earthlink.net> schrieb Well, I tested it now, but everything works as expected. Each node has it's> > In my example all nodes have an index of 0 except "Smith" and > "Larry" which each have an index of 1. Each sub tree seems to have > its own 0 based indexing. The control must have been designed that > way for some purpose. My question is . . . what purpose and how/when > would I make use of it? > > I'm a long time VB programmer who's been away from it for quite a > while and am trying to get my noggin around VB.Net. (I think this is > try #3) This treeview thing is one of many that's befuddling me. > > I feel like one of those natives in the movies that see a cigarette > lighter for the first time. Mundane if you're hip but magic if > you're not. I'm, aparantly, not. :( sub nodes. They are stored in a collection. The index is the index within this collection. For example, you can use the index to persistently store a reference to a node outside the application, like storing "2,0,1" in a file to store the user's selection when the program quits and restore it at restart. So, I don't see a problem - or I didn't get the point. Armin Hi Armin,
So, you're saying that the only intrinsic way to address a node is through "relative addressing". It appears that is apparently true but seems very inelegant and messy. At least it seems that way to me. Thank you for your help. Don On Sat, 4 Mar 2006 12:15:40 +0100, "Armin Zingler" <az.nospam@freenet.de> wrote: Show quoteHide quote >"Don" <don81846@NO_CaCa.Earthlink.net> schrieb >> >> In my example all nodes have an index of 0 except "Smith" and >> "Larry" which each have an index of 1. Each sub tree seems to have >> its own 0 based indexing. The control must have been designed that >> way for some purpose. My question is . . . what purpose and how/when >> would I make use of it? >> >> I'm a long time VB programmer who's been away from it for quite a >> while and am trying to get my noggin around VB.Net. (I think this is >> try #3) This treeview thing is one of many that's befuddling me. >> >> I feel like one of those natives in the movies that see a cigarette >> lighter for the first time. Mundane if you're hip but magic if >> you're not. I'm, aparantly, not. :( > > >Well, I tested it now, but everything works as expected. Each node has it's >sub nodes. They are stored in a collection. The index is the index within >this collection. For example, you can use the index to persistently store a >reference to a node outside the application, like storing "2,0,1" in a file >to store the user's selection when the program quits and restore it at >restart. So, I don't see a problem - or I didn't get the point. > > > >Armin "Don" <don81846@NO_CaCa.Earthlink.net> schrieb The other way to address a node is to store the reference.> Hi Armin, > > So, you're saying that the only intrinsic way to address a node is > through "relative addressing". It appears that is apparently true > but seems very inelegant and messy. At least it seems that way to > me. Armin I've extended the treenode class to add some new properties. It seems
to work well. I'm also thinking about trying to extend the nodes collection. This is my first attempt and am wondering if you have any suggestions or potential gotcha's I might prepare for. Thank you again, Don On Sat, 4 Mar 2006 21:45:39 +0100, "Armin Zingler" <az.nospam@freenet.de> wrote: Show quoteHide quote >"Don" <don81846@NO_CaCa.Earthlink.net> schrieb >> Hi Armin, >> >> So, you're saying that the only intrinsic way to address a node is >> through "relative addressing". It appears that is apparently true >> but seems very inelegant and messy. At least it seems that way to >> me. > > >The other way to address a node is to store the reference. > > >Armin
USB Pen Drive Detection - Retrieving
Dates are Evil! HELP! Class in a module or class in a class? What's going on in this ADO2 code Cannot add MSWord reference Countdown/pause/resume timer Very Unpredictable ListBox Behaviour Maximized form questions Adding New member to TextBox.. using a integer variable with a vb.net datetime literal |
|||||||||||||||||||||||