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 propperties on the datagrid.
i.e. Employee.Name, Employee.Department.Name and Employee.SalaryRange
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?
ajj3085
The problem is not with hiding some columns. The problem is to show the Salary Range of the employee
Copyright (c) Marimer LLC