storing ID's of a tree node

Hi,



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,


Database1
  | _ Table1
        |_Field1
        |_Field2
        |-Field3

  |_Table2
       |_ Field21
       |_ Field22
       |_ Field23
 
  |_ Table3
       |_Field31
       |_Field32
       |_Field33

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.
sormvAsked:
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.

_kiwi_Commented:
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.
0
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.


Thanks.
0
RomanPetrenkoCommented:
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)
<...cut...>

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];
  else
    return -1;
}
<...cut...>
Cheers!
0

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
_kiwi_Commented:
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.

Cheers,
Julien
0
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
C#

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.