Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 16-Jan-13 13:20pm
Edited 16-Jan-13 15:12pm
v4
Comments
Sergey Alexandrovich Kryukov at 16-Jan-13 18:31pm
   
Is it System.Windows.Forms? Tag it!
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Have a look at: Walkthrough: Creating a Master-Detail Windows Form[^]
 
Best regards
Espen Harlinn
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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)
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.150129.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100