Problem with Datagrid and OOP



I have been working lately in a 3-tier model which I find very
helpful. The only problem now is that I want to selectively show some
of the properties on the datagrid.
i.e. Employee.Name and Employee.SalaryType.Range


Following is a helpful example.
My case is:
- I have two different objects Employee and SalaryType
- The collection I use inherits from CollectionBase and includes
Employee.

The code I use is:
Classes & Collection

public class EmployeeCollection:CollectionBase
{
public SalesOutDetailsCollection()
{}

public int Add(Employee item)
{
List.Add(item);
return List.Count - 1;
}
}

public class Employee
{
private int _id;
private string _code;
private string _name;
private SalaryType _salary;

public int Id
{
get { return _id; }
set { _id = value; }
}

public string Code
{
get { return _code; }
set { _code = value; }
}

public string Name
{
get { return _name; }
set { _name = value; }
}

public SalayType Salary
{
get { return _salary; }
set { _salary = value; }
}
}

public class SalayType
{
private int _id;
private string _range;

public int Id
{
get { return _id; }
set { _id = value; }
}

public string Range
{
get { return _range; }
set { _ salary = value; }
}
}

public static EmployeeCollection GetList()
{
EmployeeCollection list = new EmployeeCollection();
SqlCeDataReader reader = DAL. EmployeeDB.GetList();
try
{
while (reader.Read())
{
Employee emp = new Employee();
emp.Id = Convert.ToInt32(reader("EmpId"));
emp.Code = Convert.ToString(reader("EmpCode"));
emp.Name = Convert.ToString(reader("EmpName"));
emp.SalaryType.Id =
Convert.ToInt32(reader("SalaryId"));
emp.SalaryType.Salary =
Convert.ToString(reader("SalaryRange"));

list.Add(new Employee(reader));
}
}
catch (Exception ex)
{
string msg = ex.Message;
list = null;
}
return list;
}

How can I bind this on a Datagrid and show only Employee.Name and
Employee.Salary.Range for columns?

.



Relevant Pages

  • Re: inheritance question
    ... the constructor of the Employee class should accept all parameters ... public Employee (DateTime DOB, string Address, string MaritalStatus, ... > private string mMaritalStatus; ...
    (microsoft.public.dotnet.languages.csharp)
  • Problem with Datagrid and OOP
    ... I have two different objects Employee and SalaryType ... public int Add ... private string _code; ...
    (microsoft.public.dotnet.framework.compactframework)
  • RE: How to I Start with C# Generics?
    ... > public Employee(int anId, string aName) ... > public int Id ... > public class GenericReferenceArrayListTest { ... > foreach (Employee e in employees) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: nullPointerException in abstract class
    ... | private String firstName; ... | public Employee(String first, String last, String ssn, String ...
    (comp.lang.java.programmer)
  • Re: nullPointerException in abstract class
    ... private String firstName; ... public Employee(String first, String last, String ssn, String ...
    (comp.lang.java.programmer)