// key (orderID) already exists.
if (!checkState.ContainsKey(orderID))
{
checkState.Add(orderID, (bool)e.Value);
}
else
checkState[orderID] = (bool)e.Value;
}
}
21. How do I show data that comes from two tables(TODO)?
The DataGridView does not provide any new features apart from virtual mode to enable this. What you can do is use the JoinView class described in the following article?scid=kb;en-us;325682. Using this class you can join two or more DataTables together. This JoinView can then be databound to the DataGridView.
22. 如何显示主从表?
使用DataGridView时最常见的情况之一就是主从表单,这时要显示具有主从关系的两个数据表。在主表中选择一行记录,从表中也会随之变化,显示相应的记录。
通过DataGridView控件和BindingSource 组件的交互作用来实现主从表单是非常简单的。下面的示例演示的是SQL Server的范例Northwind 中的两个表:Customers 和Orders。在主DataGridView中选择一个顾客,那么该顾客的所有订单会显示在从DataGridView 中。
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form
{
private DataGridView masterDataGridView = new DataGridView();
private BindingSource masterBindingSource = new BindingSource();
private DataGridView detaiataGridView = new DataGridView();
private BindingSource detailsBindingSource = new BindingSource();
[STAThreadAttribute()]
public static void Main()
{
Application.Run(new Form1());
}
// Initializes the form.
public Form1()
{
masterDataGridView.Dock = DockStyle.Fill;
detaiataGridView.Dock = DockStyle.Fill;
SplitContainer splitContainer1 = new SplitContainer();
splitContainer1.Dock = DockStyle.Fill;
splitContainer1.Orientation = Orientation.Horizontal;
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-50070-62.html
这个世界没人敢惹美国
让这种无良商家自生自灭吧
还在这充好人
直接击沉