0

I have three datagridviews (Department, Employee, EmployeeNotInDepartment). I have populated the Department and Employee datagridviews based on DataRelations (see below). I'm thinking there has to be an obviously easy way to populate the EmployeeNotInDepartment datagridview. Any ideas? I'm hoping that I do not have to use 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;

}
Jim Kiely
  • 365
  • 2
  • 6
  • 24
  • Any specificc reason to not use linq? It manages all the relations for you. – AlwaysAProgrammer Jul 12 '13 at 16:37
  • I know how to do it using linq but I'm wondering if there is an obviously simple way to do it using the Dataset Relations. I can't find any documentation on this approach. – Jim Kiely Jul 12 '13 at 16:56

2 Answers2

0

If you insist on not using LINQ then you can use DataView and specify your filter in the RowFilter property (it could be a Comma seperated list of Ids that you don't want to show)

This is how to use RowFilter on a DataView

Rwiti
  • 1,056
  • 1
  • 13
  • 31
0

As suggested by @Rwiti, you could use RowFilter property of DataView and you can define proper expression to filter out rows based on that.

Check out below link that list out various examples of RowFilter including NOT IN

http://www.csharp-examples.net/dataview-rowfilter/

But if you're not having any reason for not using Linq (i.e have to work with .net 2.0) then go for it.

Nilesh Thakkar
  • 2,877
  • 1
  • 24
  • 43