下载了微软的datagridview的示例,显示父子表的部分看不懂,请教一下?
private void ViewOrders(string customerID)
{
this.Cursor = Cursors.WaitCursor; // Show the CustomerOrders dialog, passing in the customer ID.
CustomerOrdersForm co = new CustomerOrdersForm(); // Get the related list of orders for the current customer.
CurrencyManager cm = ((CurrencyManager)this.BindingContext[northwindDS, "Customers.CustOrders"]);
IBindingListView list = (IBindingListView)cm.List; co.ShowDialog(customerID, this, list); this.Cursor = Cursors.Default; }"Customers.CustOrders" 是什么意思?如果有一个DataSet,有两个表主表table1,从表table2,用ID关联这个地方应该怎么写?谢谢!
private void ViewOrders(string customerID)
{
this.Cursor = Cursors.WaitCursor; // Show the CustomerOrders dialog, passing in the customer ID.
CustomerOrdersForm co = new CustomerOrdersForm(); // Get the related list of orders for the current customer.
CurrencyManager cm = ((CurrencyManager)this.BindingContext[northwindDS, "Customers.CustOrders"]);
IBindingListView list = (IBindingListView)cm.List; co.ShowDialog(customerID, this, list); this.Cursor = Cursors.Default; }"Customers.CustOrders" 是什么意思?如果有一个DataSet,有两个表主表table1,从表table2,用ID关联这个地方应该怎么写?谢谢!
yourDataSet.Relations.Add( "Customers.CustOrders",
yourDataSet.Tables["Customers"].Columns["ID"],
yourDataSet.Tables["CustOrders"].Columns["ID"] );
从数据源面板把Customers表和Orders表拖进Form上。
注意,这里有个关键,拖Orders表时,是从Customers节点的子节点里找到Orders表,把它拖到Form上,而不是和Customers表同一层的那个Orders表。就这么简单,当你在显示Customers表的DataGridView上浏览时,显示Orders表的DataGridView会显示对应的订单。其实是二个BindingSource‘串接’在一起了。
ordersBindingSource.DataSource = customersBindingSource;
ordersBindingSource.DataMember = "表之间的关系"; //什么FK_...?,忘了。
如果想使用此功能,必须使用DataGrid