[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

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.
  • 2
1 Solution
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;
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now