WinForm 2.0 有代码两个DataGridView实现Master/Details
来源:互联网 发布:矩阵式项目管理组织 编辑:程序博客网 时间:2024/06/05 20:30
private void GetData()
{
try
{
// Specify a connection string. Replace the given value with a
// valid connection string for a Northwind SQL Server sample
// database accessible to your system.
String connectionString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
SqlConnection connection = new SqlConnection(connectionString);
// Create a DataSet.
DataSet data = new DataSet();
data.Locale = System.Globalization.CultureInfo.InvariantCulture;
// Add data from the Customers table to the DataSet.
SqlDataAdapter masterDataAdapter = new
SqlDataAdapter("select * from Customers", connection);
masterDataAdapter.Fill(data, "Customers");
// Add data from the Orders table to the DataSet.
SqlDataAdapter detailsDataAdapter = new
SqlDataAdapter("select * from Orders", connection);
detailsDataAdapter.Fill(data, "Orders");
// Establish a relationship between the two tables.
DataRelation relation = new DataRelation("CustomersOrders",
data.Tables["Customers"].Columns["CustomerID"],
data.Tables["Orders"].Columns["CustomerID"]);
data.Relations.Add(relation);
// Bind the master data connector to the Customers table.
this.bindingSource1.DataSource = data;
this.bindingSource1.DataMember = "Customers";
// Bind the details data connector to the master data connector,
// using the DataRelation name to filter the information in the
// details table based on the current row in the master table.
this.bindingSource2.DataSource = bindingSource1;
this.bindingSource2.DataMember = "CustomersOrders";
}
catch (SqlException)
{
MessageBox.Show("To run this example, replace the value of the " +
"connectionString variable with a connection string that is " +
"valid for your system.");
}
}
private void Form1_Load(object sender, EventArgs e)
{
// Bind the DataGridView controls to the BindingSource
// components and load the data from the database.
this.dataGridView1 .DataSource = bindingSource1;
this.dataGridView2.DataSource = bindingSource2;
GetData();
// Resize the master DataGridView columns to fit the newly loaded data.
dataGridView1.AutoResizeColumns();
// Configure the details DataGridView so that its columns automatically
// adjust their widths when the data changes.
dataGridView2.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.AllCells;
this.bindingNavigator1.BindingSource = this.bindingSource1;
}
- WinForm 2.0 有代码两个DataGridView实现Master/Details
- WinForm 2.0 无代码DataGridView绑定
- [WinForm]Datagridview 实现二维表头
- WinForm中两个DataGridView同时滚动
- Winform中DataGridView有自动添加行!
- winform dataGridView DataGridViewComboBoxColumn 下拉框事件代码
- winform datagridview IList datasoure 实现排序
- WinForm下DataGridView导出Excel的实现
- C#WINFORM 的DATAGRIDVIEW多表头实现
- winform DataGridView实现用shift多选checkbox
- C#Winform:DataGridView 简单分页实现
- .NET Winform Datagridview 实现多行表头
- C# Winform DataGridView 公共分页实现
- C# Winform DataGridView分页功能的实现
- C# Winform DataGridView 公共分页实现
- C# Winform DataGridView 公共分页实现
- 两个winform之间传数据方法,将datagridview数据传到另一个winform界面去,取出datagridview中选定的某行某列
- .NET 2.0 - WinForm Control - DataGridView 编程
- 翻译(二)SharePoint 2007管理入门:Windows SharePoint Service 3.0 and Microsoft Office SharePoint Server 2007
- SQL高级应用
- WebQQ
- J2EE
- IE6 对浮动元素内的未指定宽度的块级元素错误的解释 BUG
- WinForm 2.0 有代码两个DataGridView实现Master/Details
- nutch-0.8在eclipse中运行
- WinForm 2.0 textBox作为参数的查询,显示在DataGridView
- asp.net中正则表达式常用说明
- WinForm 2.0 下拉框的绑定
- WinForm 2.0 无代码DataGridView绑定
- WinForm 2.0 应用一 无代码实现详细信息绑定
- Iterator源码剖析
- 正则表达式-ASP.NET