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;