WinForm 2.0 无代码两个DataGridView实现Master/Details

本文介绍了一种在WinForms应用程序中实现父子表数据绑定的方法。通过使用BindingSource组件,可以轻松地将父表(客户信息)与子表(订单信息)关联起来,并在两个DataGridView控件中显示这些数据。此外,还展示了如何设置导航栏以方便用户在记录间进行切换。

private void OnFormLoad(object sender, EventArgs e)
{
// Get the data set with parent / child tables into a data set
CustomersDataSet customers = CustomersDataSet.GetCustomers();
// Set up the data sources normally for the first grid
m_CustomersBindingSource.DataSource = customers;
m_CustomersBindingSource.DataMember = "Customers";
m_CustomersGrid.DataSource = m_CustomersBindingSource;
// Set up the data sources for the child source to point to
// the parent source, and the contained relation
m_ChildOrdersBindingSource.DataSource = m_CustomersBindingSource;
m_ChildOrdersBindingSource.DataMember = "FK_Orders_Customers";
// Child grid to child connector
m_OrdersGrid.DataSource = m_ChildOrdersBindingSource;
// Navigator to parent connector
m_BindingNavigator.BindingSource = m_CustomersBindingSource;
}

转载于:https://www.cnblogs.com/czh-liyu/archive/2007/11/25/971990.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值