Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > showing 2 tables in a DataGridView using DataRelation
 

showing 2 tables in a DataGridView using DataRelation

Here i made relation between StudentDetails and MarkDetails table. I want to show this 2 tables in a single
DataGridView as a TreeView.Following are the sample code....

obj.cmd =

new System.Data.SqlClient.SqlCommand("select * from student_details", obj.connect());obj.ad.SelectCommand = obj.cmd;
obj.ad.Fill(obj.ds,
"STUDENT");
obj.cmd =
new System.Data.SqlClient.SqlCommand("select * from mark_details", obj.connect());
obj.ad.SelectCommand = obj.cmd;
obj.ad.Fill(obj.ds,
"MARK");
obj.ds.Relations.Add("Student_Mark", obj.ds.Tables["STUDENT"].Columns["reg"], obj.ds.Tables["MARK"].Columns["reg"]);

dataGridView1.DataSource = obj.ds;

but i get an empty dataGridView while running.i'm using .net 2005
can anyone help me......

jini_kumar  Friday, August 07, 2009 7:31 AM

Hi,

When binding to a data source that contains multiple lists or tables, you must set the DataMember property to a string that specifies the list or table to bind to. So if you want the DataGridView to show the data, you need to set the dataGridView1.DataMember to “STUDENT�or “MARK�

Base on my understanding, you want to show master-details in one DataGridView. The DataGridView does not support for showing master-details data in the same DataGridView. You can try previously shipped window forms datagrid control.

More information:

DataGridView.DataSource Property

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx

Creating Master-Details Lists with the Windows Forms DataGrid Control

http://msdn.microsoft.com/en-us/library/aa984328(VS.71).aspx

How to: Create a Master/Detail Form Using Two Windows Forms DataGridView Controls

http://msdn.microsoft.com/en-us/library/c12c1kx4.aspx

FAQ 31. How do I show master-details?

FAQ 32. 32. How do I show master-details in the same DataGridView?

If I misunderstood you, or you have further questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, August 11, 2009 3:36 PM

Hi,

When binding to a data source that contains multiple lists or tables, you must set the DataMember property to a string that specifies the list or table to bind to. So if you want the DataGridView to show the data, you need to set the dataGridView1.DataMember to “STUDENT�or “MARK�

Base on my understanding, you want to show master-details in one DataGridView. The DataGridView does not support for showing master-details data in the same DataGridView. You can try previously shipped window forms datagrid control.

More information:

DataGridView.DataSource Property

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx

Creating Master-Details Lists with the Windows Forms DataGrid Control

http://msdn.microsoft.com/en-us/library/aa984328(VS.71).aspx

How to: Create a Master/Detail Form Using Two Windows Forms DataGridView Controls

http://msdn.microsoft.com/en-us/library/c12c1kx4.aspx

FAQ 31. How do I show master-details?

FAQ 32. 32. How do I show master-details in the same DataGridView?

If I misunderstood you, or you have further questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, August 11, 2009 3:36 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView and BindingNavigator modifiers problem
• MaskedTextBox doesn't display leading zero for datetime column from SQL 2000 table
• Bindingsource - Is there event any equivalent to positionchangING.
• Row selecting problem
• Add a total row to a DataGridView
• Get addition key that were "pressed" when ColumnHeaderMouseClick triggers
• Highlight the cell with an error.
• Filtering datagridview based on it's ComboBoxType column
• Custom object collection to a GridView control
• filling a dataset from a recordset