Results 1 to 5 of 5

Thread: Tree hierarchy

  1. #1

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Tree hierarchy

    I'm making a chat server with a bunch of different rooms. Chat rooms will be stored in a "tree hierarchy" form, like this (think of a message board like this one):

    Code:
    Category 1
        Room 1
        Room 2
        Room 3
    
    Category 2
        Sub category 1
            Room 1
            Room 2
            Room 3
    I will be storing and using them from a UDT array, similar to this:

    Code:
    Type CHAT_ROOM
        dblID As Double 'ID of chat room.
        dblParentID As Double 'ID of parent room/category.
        strName As String 'Name of chat room/category.
        IsRoom As Boolean 'To tell if it is a chat room or a category.
    End Type
    
    Private udtRooms() As CHAT_ROOM 'Array to store all chat rooms.
    There's actually a lot more properties than that, but that's the basic form.

    I'm getting confused on how to set the parent ID for each item. I'm making a dialog in the server so I can create/edit the default chat rooms.

    When someone joins a room the client will refer to the room's ID instead of the name, ie:

    "JOIN #room number"

    I attached a screenshot.
    Last edited by DigiRev; Mar 26th, 2007 at 02:54 AM.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Tree hierarchy

    not sure what you are asking?

    but treeview Keys are strings

    Code:
    Optional. A unique string that can be used to retrieve the Node with the Item method
    as long as each category/sub category has only one entry.. then use the category name... children can have the key blank so as long as you point to the correct parent.. good to go
    but really.. the node itself has this info.. just use the TAG property to say room or category
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Tree hierarchy

    Quote Originally Posted by Static
    not sure what you are asking?

    but treeview Keys are strings

    Code:
    Optional. A unique string that can be used to retrieve the Node with the Item method
    as long as each category/sub category has only one entry.. then use the category name... children can have the key blank so as long as you point to the correct parent.. good to go
    but really.. the node itself has this info.. just use the TAG property to say room or category
    I will be working with the rooms from the UDT array, not from the TreeView control.

    I'm kind of confused on how I should do this.

    The parent id's will be like this. For root categories, it will just be their ID.

    IDs are in blue, parent IDs are in red.

    Code:
    Category 1 (1)
        Room 1 (1)
        Room 2 (1)
    
    Category 2 (2)
        Sub category 1 (2) (3)
            Room 1 (3)
            Room 2 (3)
            Room 3 (3)
        Sub category 2 (2) (4)
            Room 1 (4)
            Room 2 (4)
    I know, it's confusing.

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Tree hierarchy

    looks good to me? im not sure what the confusion is

    why wont that work? (except for the fact that u cant use numbers as node keys... so if you need to load the tree from the array of UDT's then it wont work... just make them strings and add "K" in front of each
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Tree hierarchy

    Rather than using a UDT create a class instead which will be added to collections. You will then be maintaining two collections, one collection for the tree the other for the rooms (to facilitate room selection). The complete room info class will be added to the rooms collection, reference each room through its key. The tree collection can contain the keys of the rooms in the rooms collection, like an array containing index info to access another array, in addition to parent sibling info similar to those of nodes in a treeview... or skip that and just use the treeview control for the heirarchy.

    Collections are easier to manage (add, remove) compared to an array of udts. You can easily move them around the tree heirarchy if you need to do so. And you can assign methods to the classes to facilitate processes such as GetUsers(), Kick(username), Join(username) methods. The two collections (or collection plus reference to treeview) mentioned can also be children of another class (eg. classChat) which has methods to facilitate synchronization of the rooms and tree heirarchy, when a room is set for deletion it is deleted in both collections by the parent class's relevant method.

    You can maintain part of your numeric ID system (eg. info sent between client/server) to make the numeric ID into a key just prepend a character (eg. "a" & 1), to revert the collection key back to numeric strip the leading character.

    You can extend it further and also use classes/collections for users.
    Last edited by leinad31; Feb 28th, 2007 at 01:08 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width