storing ID's of a tree node

Posted on 2004-11-12
Last Modified: 2010-04-15

I am having a XML File, and contains databse name,id, table names,table ids, field names,ids. I am populating a tree from this data like,

  | _ Table1

       |_ Field21
       |_ Field22
       |_ Field23
  |_ Table3

user can select and add fileds from tree to a listview or he can drag drop fields from tree to listview.Depending on the user selected fields, I am stroring field IDS now.

I need to store the Table ID's also. I have to use thses ID's in creating a SQL statement dynamically.

User can select one or more fields from each table and I need to store distinct table ID's.

I implemeted all the functionality except storing table ID's.

Any Ideas!!

Thanks In Advance.
Question by:sormv
    LVL 3

    Expert Comment

    You have a property called "Tag" in the TreeNode object in WinForms, just use it to store the table Ids for Table Nodes, and fetch it from the selection when creating your sql statement.

    Author Comment

    Hi Kiwi,

    I am using Tag property of treenode for  setting the table id's. But if you select multiple field id's from the same table u will be having same table id with multiple times.I need to have distinct table id's for the user selected fields from different tables.

    Is there is any way, I can store table id's in a array and I can select distinct table IDs  from that.

    LVL 8

    Accepted Solution

    Hi sormv,
    Why don't you use Hashtable for your needs? just create some private hashtable in your form (or even in the tree control if if you use your own tree ctrl)

    Hashtable table = new Hashtable()

    private void AddTreeNodeToHash(TreeNode node, int tablID)
      table[node] = tablID;
    //if returned -1 no tableid found
    private int GetTableIdByNode(TreeNode node)
      if (table.ContainsKey(node))
        return table[node];
        return -1;
    LVL 3

    Expert Comment

    Sorry for the response delay.

    Here is what you have:
    - First step, You can point to the tree nodes of the original treenode in your listview (still this Tag property).
    - Second step, you have the field id in your treenode (Tag).
    - Finally, you have the table name in the table treenode (Tag).

    Now what you can do:
    In the field treenode, you have a Parent property pointing to the parent node in the treenode.
    So all you have to do is: ((TreeNode) myListViewItem.Tag).Parent.Tag, and you will have the treenode.

    If this does not work, Tag contains an object, so why not create a class, like :
    struct MyField
    string tableName;
    string fieldName;
    and put it in the Tag of your treenodes.


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now