Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView vs DataGrid bound to DataView
 

DataGridView vs DataGrid bound to DataView

I have DataView containing a DataSet with a relation defined between 2 tables. When I bind the DataView to the DataGrid, the grid displays both parent and child tables just fine. But when I gind the DataView to the DataGridView, the grid only displays the first table. Any thoughts out there?

----------code snippet----------------
-- Fill tables, set relation, fill data view --------------------

String sql1 = "Select * from user_def order by login_id";
String sql2 = "Select * from user_app_auth order by login_id, env_id, app_name";
String table1 = "user_def";
String table2 = "user_app_auth";
String relationName = "user_app";
String key = "login_id";

SqlConnection
sqlConn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI;" + "Initial Catalog=user_profile");
DataSet ds = new DataSet();
sqlConn.Open();

SqlDataAdapter dataAdapter = new SqlDataAdapter(sql1, sqlConn);
dataAdapter.Fill(ds, table1);
dataAdapter =
new SqlDataAdapter(sql2, sqlConn);
dataAdapter.Fill(ds, table2);

DataRelation relation = new DataRelation(relationName,
ds.Tables[table1].Columns[key],
ds.Tables[table2].Columns[key],
false);
ds.Relations.Add(relation);

DataView dv = new DataView(ds.Tables[table1]);

sqlConn.Close();

----- bind to DataGrid ------
this.dataGrid1.DataSource = dv;

----- bind to DataGridView -----
this.dataGridView1.DataSource = dv;

Augie  Wednesday, September 21, 2005 5:46 AM
The DataGridView was designed to display only the parent table.

Hope this helps.

Daniel.

This posting is provided "as-is".
Daniel Herling - Student  Wednesday, September 21, 2005 4:52 PM
The DataGridView was designed to display only the parent table.

Hope this helps.

Daniel.

This posting is provided "as-is".
Daniel Herling - Student  Wednesday, September 21, 2005 4:52 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView row height
• IList<T> Woes
• Datagridview nullreference exception
• Form Designer Error "An attempt to attach an auto-named database ........... "
• Master Details Forms with 2 DataGridView Child Grid doesn't clear when Clear the parent Grid
• How to prevent selected row go down when pressing enter in datagridview?
• Updating Many-to-Many Relations via Two Listboxes
• Overwrite DataGridView header Shift + Click event
• datagridview: show a value instead of the one in the db
• How to set max length of datagridview column?