+ Reply to Thread
Results 1 to 15 of 15

using a treeview

  1. #1
    Registered User
    Join Date
    03-12-2009
    Location
    Breda, Netherland
    MS-Off Ver
    Excel 2003
    Posts
    27

    using a treeview

    Hello,

    I want too use a treeview in my userform.

    In my program I connect too a OPC server the OPC server contains different channels, those channels contains devices and the devices contain items, those items could be a collection of items or individual items.

    I have already used a listbox and listview in my userform, but i'm not particulary happy with the results. So i want too add the treeview because i think it would look and work better.

    I'll add all of my code and i hope you can see what i mean. I have found some examples but they use data on a worksheet which is a bit different too how i want too do it. I have found out the .add that is used there doesn't work and i'm having trouble finding what i need. for some reason opening the help files is blocked on win xp.

    Please Login or Register  to view this content.

    I know it's a bit much, but i'd rather added too much code then you guys need too ask that i add some pieces.

    I hope you can help me it would be appreciated.

    greetings Dadio25

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Some help with using a treeview

    Have you seen this example?
    http://puremis.net/excel/code/080.shtml

    In what way does you code not work?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    03-12-2009
    Location
    Breda, Netherland
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Some help with using a treeview

    Well in that example you use a .add too add something too the tree. But in my program i don't use the worksheet too get data from. so that .add doesn't work for my program.

    But I also don't know how many nodes I need too add so that's a bit of a problem there also.

    In the code i gave you I removed how I tried it because it didn't work. But I found that if i use the add from nodes it should work. so i'm trying too do that at the moment.

  4. #4
    Registered User
    Join Date
    03-12-2009
    Location
    Breda, Netherland
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Some help with using a treeview

    Nobody can help me then?

    I'm just wondering how i would be able too use the treeview. The hierarchy of what i want too show is very much like a filedirectory.

    I have that server. Which could have several channels so i need too count those first. A channel could have one device or more need too count that again. A device could have several items so that needs too be count again. but those items could be the end or an item could have several items of his own. So need too count that again.

    I believe I have the functions found too count it, but they give their answer as a long.

    How do I make from what I above described a usuable treeview? I need too work with arrays that is obvious. and they need too be made and filled first.

    But do I need too make an array for each channel with devices. then an array for each of those devices with items and then possibly and array for an item of they have several items underneath themselves.

    greetings dadio25

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Some help with using a treeview

    It's very difficult for anybody to help as we can not use your code.
    Firstly it is incomplete in that we don't know what the objects such as OPCServer are. And even if we did have full code we can not test as it is specific to you environment.

    All we can do is point out how the population takes place.

    If you had already coded 2 listboxes you must know the structure from your objects. It would just be a case of using those objects to build the tree.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Some help with using a treeview

    Here is another example using arrays.
    http://people.revoledu.com/kardi/tut...6/Treeview.htm

    You will find most examples are for VB but the principle should be the same for VBA

  7. #7
    Registered User
    Join Date
    03-12-2009
    Location
    Breda, Netherland
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Some help with using a treeview

    Hmmm I understand your dilemma,

    I am using an dll called opcdaauto which is a specification from the opcfoundation. It specifies a way too connect too an opc server.

    I have one listbox that is working fully bit it gets populated by using the opcmybrowser.

    And the population is part of the problem. The problem is i don't really understand how those nodes work and how too populate them. Since most examples use a tree that has a fixed number of nodes already made. But that isn't possible for me. I first need tooo find out how many nodes i need and then i need too think about how too populate them. How do you recommend I do that?

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Some help with using a treeview

    This is a very quick and dirty example that builds a treeview of the first 2 levels of your folder structure on the C drive.

    Create a userform with a treeview and command button.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-12-2009
    Location
    Breda, Netherland
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Some help with using a treeview

    Hmmm,

    I'm trying too add the first nodes. I add the very first node using
    Please Login or Register  to view this content.
    in which OPC serverstring is the name of the server.

    Then i want too add the other nodes and I use
    Please Login or Register  to view this content.
    I use the for loop too browse via the opcmybrowser for each name (vName) that gets found then i add those too a listbox and then i want too add them too the treeview, but it doesn't try too add something it just stops their.

    So I know I made an error, but i'm wondering what exactly i did wrong. I use the variable vName as a variant.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Some help with using a treeview

    You are using the root display text rather than the key.


    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    03-12-2009
    Location
    Breda, Netherland
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Some help with using a treeview

    Hello, I tried too use that and it doesn't give an error, but it doesn't show anything.

    It just keeps showing the the first node I made and not what I try too add

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Some help with using a treeview

    did you expand the node? Either with code or by double clicking the node.

  13. #13
    Registered User
    Join Date
    03-12-2009
    Location
    Breda, Netherland
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Some help with using a treeview

    Hello,

    Yes I tried too expand the node, but that didn't work. I stepped through my program and found that the variabele Nodx stays the same. So too see what happens i made another node named childnode in which I try too set what I want too add and it says during step childnode = Nothing.

    So obviously i'm doing something wrong. I even tried too give the childnode a unique key by adding something too the key, but that didn't work too.

    Have you got any ideas?

    greetings

    PS : no matter I solved it I used mainfrm.OPCtree instead of just OPCtree and I needed too make the key of the childnodes unique and now it works.
    Last edited by dadio25; 03-18-2009 at 11:21 AM. Reason: one problem solved millions too go

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Some help with using a treeview

    nothing more that I have already suggested and provide I'm afraid.

  15. #15
    Registered User
    Join Date
    03-12-2009
    Location
    Breda, Netherland
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Some help with using a treeview

    I know but after a while you just can't see the problem anymore sigh

    but thanks for the help until now

    greetings

+ 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