Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

I am struggling as to display parent and child details in one datagridview using vb.net (VS2012) in win form with sample as following:

in datagridview shows first column with "+" or first column name is "+"
+ ID, NAME,..
+ ID, NAME,..

When Click + at parent row and result should be as

- ID, NAME
ID, ORDER, AMOUNT..
ID, ORDER, AMOUNT..
+ ID, NAME,..
+ ID, NAME,..

Thanks in advance for any idea and help.

Ooops, I should tell more details as : I create datarelation
Dim relation As DataRelation
Dim table1Column As DataColumn
Dim table2Column As DataColumn

table1Column = ds.Tables("Table1").Columns(0)
table2Column = ds.Tables("table2").Columns(0)
relation = New DataRelation("relation", table1Column, table2Column)

ds.Relations.Add(relation)
datagridview1.Datasourse = ds.Tables(0)
In datagridview displays only "parent table" not included "child table"

I appreciate so much for your reply from the world (Thanks from Australia)
Posted
Updated 16-Jan-13 14:12pm
v4
Comments
Sergey Alexandrovich Kryukov 16-Jan-13 18:31pm    
Is it System.Windows.Forms? Tag it!
—SA

If you use a DataSet that defines the relationship between the tables, the framework will handle the rest. But I have found that a TreeView works better.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Jan-13 18:49pm    
Agree. We were answering at the same time. My 5.
I found one interesting option, put in my answer — please see.
—SA
If child-parent relation is really involved, the better control could be TreeView. With it, you will loose all your column data, but you can use both controls. When selection in TreeView changes, you can handle respective events and show detail data in some other control accordingly. This is easy enough.

There is another approach. Peter Brightman demonstrated how the ListView control can be used in virtual mode to represent both tree structure and node detail with columns. Please give it a try. Even though he did not create a fully-fledged control out of it, it looks and works really well and can be very useful:
Virtual Mode TreeListView[^].

Good luck,
—SA
 
Share this answer
 
Have a look at: Walkthrough: Creating a Master-Detail Windows Form[^]

Best regards
Espen Harlinn
 
Share this answer
 
Thanks Sergey, ListView demonstrated by Peter Brightman is a good one to see, but my project needs DatagridView or Datagrid (I work with a fuzzy boss)
 
Share this answer
 

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