我有三个数据网格视图(部门、员工、EmployeeNotInDepartment)。我已经根据 DataRelations 填充了 Department 和 Employee 数据网格视图(见下文)。我认为必须有一种明显简单的方法来填充 EmployeeNotInDepartment 数据网格视图。有任何想法吗?我希望我不必使用 linq。
public Form1()
{
InitializeComponent();
dtDepartment = FillDepartmentList();
dtEmployee = FillEmployeeList();
dsDepartmentEmployees = new DataSet();
// Add tables to dataset
dsDepartmentEmployees.Tables.Add(dtDepartment);
dsDepartmentEmployees.Tables.Add(dtEmployee);
// Create table relationship
dsDepartmentEmployees.Relations.Add("DepartEmpRelation", dtDepartment.Columns["DepartmentNumber"], dtEmployee.Columns["DepartmentNumber"],true);
BindingSource bsDepartment = new BindingSource();
bsDepartment.DataSource = dsDepartmentEmployees;
bsDepartment.DataMember = "table1";
BindingSource bsEmployee = new BindingSource();
bsEmployee.DataSource = bsDepartment;
bsEmployee.DataMember = "DepartEmpRelation";
dataGridView1.DataSource = bsDepartment;
dataGridView2.DataSource = bsEmployee;
}