我一直在試圖從dataGrid中顯示某個選定父節點的所有子節點。我用這個教程作爲指導http://msdn.microsoft.com/en-us/library/vstudio/y8c0cxey%28v=vs.100%29.aspx,但沒有運氣。這裏是我的代碼:獲取數據行的子節點
的datagridview的private void getData()
{
SqlDataAdapter parentDataAdapter = new SqlDataAdapter("select * from Airline", connection);
parentDataAdapter.Fill(ds, "Airline");
SqlDataAdapter childDataAdapter = new SqlDataAdapter("select * from Plane", connection);
childDataAdapter.Fill(ds, "Plane");
DataColumn parentColumn = ds.Tables["Airline"].Columns["airline_id"];
DataColumn childColumn = ds.Tables["Plane"].Columns["airline_id"];
relation = new DataRelation("pln_air", parentColumn, childColumn);
ds.Relations.Add(relation);
parentBindingSource.DataSource = ds;
parentBindingSource.DataMember = "Airline";
childBindingSource.DataSource = parentBindingSource;
childBindingSource.DataMember = "Plane";
}
單元內容Click事件是爲下:
private void dg_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
parentDataGridView.DataSource = parentBindingSource;
childDataGridView.DataSource = childBindingSource;
getData();
}
我的問題是,當我運行它,我點擊一個細胞,我得到一個錯誤:DataMember property 'Plane' cannot be found on the DataSource.
任何人都可以幫助我嗎?
檢查這個http://stackoverflow.com/questions/12677156/datamember-property-type-cannot-be-found-on-the-datasource – Muath
'getData()'在綁定數據源後被調用。檢入'dg_CellContentClick'事件 – Hassan
那麼我應該何時打電話給它? – user3421241