我有三个数据网格视图(部门、员工、EmployeeNotInDepartment)。我已经基于DataRelations填充了部门和员工数据网格视图(见下文)。我认为肯定有一种明显简单的方法来填充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;
}发布于 2013-07-13 01:11:49
如果您坚持不使用LINQ,那么您可以使用DataView并在RowFilter属性中指定您的过滤器(它可能是您不想显示的in的逗号分隔列表)
在DataView上使用RowFilter的This is how
发布于 2013-07-13 01:18:52
正如@Rwiti所建议的,您可以使用DataView的RowFilter属性,并且可以根据该属性定义适当的表达式来筛选出行。
请查看以下链接,其中列出了包括NOT IN在内的各种RowFilter示例
http://www.csharp-examples.net/dataview-rowfilter/
但是,如果你没有任何理由不使用Linq (即必须使用.net 2.0),那么就使用它。
https://stackoverflow.com/questions/17619717
复制相似问题