storing ID's of a tree node


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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
sormvAuthor Commented:
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.

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;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.