Problem with Datagrid and OOP
- From: yiannisezn@xxxxxxxxx
- Date: 27 Mar 2007 23:26:56 -0700
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?
.
- Prev by Date: Re: downloading a single file using multiple threads
- Next by Date: Re: Question about unpack
- Previous by thread: Re: Converting C# string to char*
- Next by thread: Re: validate that string input is a negative number
- Index(es):
Relevant Pages
|