Click here to Skip to main content
15,896,439 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am asked to make a datagridview that shows the hierarchy of tables from parents>sub-parents>child.
I don't know how to put up a picture here so to give you a clear view of what I want to make is, imagine an ms access database with 3 tables named "Parent","Sub-parent" and "child". "Parent" is in the top of the hierarchy, connected to "Sub-Parent" with a foreign key. While the "Sub-Parent" table connected to the "Child" table, the same way "Sub-Parent" is connected to "Parent" table.

In the access, when you looked at the "Parent" table, you will be able to drop-down it to see the "Sub-Parent" data row until the "Child" data row whenever it corresponds with the primary key.

You see, I want to recreate that into visual basic style. I saw some downloadable treeview sample progs here but it is too advanced for me to study and uses some css/wpf thing that I don't have a single clue about.
Posted
Comments
Ralf Meier 15-Jul-15 2:25am    
So ... you have a datatable and you want to display it's structure with as treeview ?
Does your datatable has a fixed structure and you only want to display the items in the treeview ?

Perhaps you should deliver more Information ... (and improve your question)
Jake Robert 15-Jul-15 3:15am    
Yes, I do want my datatable to be displayed

The actual treeview hierarchy that I will be doing is like this, Sector>Association>Company>Location>Product>Raw Materials. So 1 Parent will be having multiple sub-parents and child.




Ralf Meier 15-Jul-15 3:43am    
OK ... understand ...
So - please tell me where the problem is / where you stuck ...
Jake Robert 15-Jul-15 4:13am    
Actually, I am stuck at all. I do not know how to start. I can't even connect the treeview to my database's datatable. So any enlightenment into this matter is highly appreciated.
Ralf Meier 15-Jul-15 8:57am    
Isn't my solution what you wanted to see ?
If Not - please give me more information - perhaps about your datatable ...

1 solution

As I understand your problem :
The TreeView-Control could not be directly connected to your datatable(s). What you have to do is the following :
- according to the structure of your data create the TreeNodes (and give them the corresponding Name). This could be done manually (with the Control-Designer) if the structure is allways the same. Or it must be done dynamicly if the structure is different. This works like this :
- Add a TreeNode and Name it
- select this TreeNode and add all necessary sub-Nodes and Name them.
- select this TreeNode.SubNode and add all necessary sub-Nodes and Name them.
- and so on.

Do you think that you could try it like this ?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900