Re: Treeview help




"Bob Butler" <tiredofit@xxxxxxxxxx> wrote in message
news:eFOAA7bCGHA.2036@xxxxxxxxxxxxxxxxxxxxxxx
> "MikeD" <nobody@xxxxxxxxxxx> wrote in message
> news:OsqnrfbCGHA.3920@xxxxxxxxxxxxxxxxxxxx
>> <Fern G> wrote in message news:ubx6w6WCGHA.916@xxxxxxxxxxxxxxxxxxxxxxx
>> Set mynod = TreeView1.Nodes.Add(mynod.Key, tvwChild, s1(i), s1(i))
>
> As an aside... the first argument is a reference to the parent. You can
> pass a key and the control will do a lookup to find the mode but since you
> already have the reference it's simpler just to use it:
> Set mynod = TreeView1.Nodes.Add(mynod, tvwChild, s1(i), s1(i))


I didn't know you could pass a reference to a Node object for the first
parameter. I thought it had to be an index or a key (IOW, an integer or a
string). I wonder.....would a reference to a Node object get passed....or
would the default property of the Node object get passed (which I believe is
the Text property)? In any case, I don't think passing a Node object is a
good idea. If nothing else, there's uncertainty (IMO) of what's actually
getting passed. Is it a reference to a Node or is it the default property of
the Node object?

> But I'd probably assign the reference to a new variable so that you don't
> lose the parent reference if it works.

Good advice. If you look back at the example I provided, there are separate
variables for the root nodes, the child nodes, and the grandchild nodes. The
reason behind that is so that you don't lose those references. Of course,
you can easily get a reference to the parent from the Parent property of the
Node (and you can, if necessary, keep on backing up: Node.Parent.Parent).
But that can get confusing.

What matters most is writing clear and concise code. If it means declaring
several object variables, so be it. If you can write clear and concise code
using properties, that's OK too. But except for simple routines, it's not as
likely the code will be as clear as if you used different variables.


--
Mike
Microsoft MVP Visual Basic


.



Relevant Pages

  • Re: owner of class
    ... >> terminate a given object but because I've created circular reference, ... > Public Sub AttachParent ... > Then each class you need to know it's parent object can simply implement ... > Private Sub IParentTrack_AttachParent ...
    (microsoft.public.vb.general.discussion)
  • Re: Can objects be passed around as in Java?
    ... > Each oMACdefn contains oFUNCTdefn objects of class clsFUNCTdefn5A. ... > main line doesn't seem to pass me a good wsWorksheet, ... Public) object variable to retain the reference. ... Public Property Get Parent() As clsMACdefn5A ...
    (microsoft.public.excel.programming)
  • Re: Getting components name from notification parameter?
    ... >> Does Freeing it also clear the reference? ... is that the outer object has no need to know about the inner object. ... > but still demands a parent window on startup. ... TTranslate is a TComponent, not a TWinControl. ...
    (alt.comp.lang.borland-delphi)
  • Re: Re: BUG in: Driver core: convert block from raw kobjects to core devices (fwd)
    ... "drop reference to parent kobject at remove time instead of release ... with how it deals with the driver model, but I need to take the time to ... but as other block device drivers create the ... parent until it is released. ...
    (Linux-Kernel)
  • Re: Inheritance Collection Classes
    ... parent class other than passing it to the child. ... > have a reference to the Customer class; ... create your class Emails with a constructor which take the ... >> of collection classes each passing a reference to the parent object down ...
    (microsoft.public.dotnet.languages.vb)