R
RedLars
Hi,
Trying to get an handle on the property grid which I'm finding very
handy.
I got one problem though that I have not been able to fix.
Here is a small example to illustrate the problem;
Say I want to display a list of employee's with their Name, Position
and Salary in a propertygrid. So far so good.
public class Employee
{
private string _Name = "";
private string _Position = "";
private int _Salary = "";
[DisplayNameAttribute("Employee Name")]
public string Name
{
get { return _Name}
set { _Name= value; }
}
[DisplayNameAttribute("Employee Position),
DescriptionAttribute("TODO")]
public string Position
{
get { return _Position}
set { _Position= value; }
}
[TypeConverter(typeof(ListConverter)),
DisplayNameAttribute("Employee Salary"), DescriptionAttribute("TODO")]
public int Salary
{
get { return _Salary}
set { _Salary= value; }
}
}
By adding a ListConverter I'm able to get a drop down list of all the
options available. However, the same list would apply for all
employees. How can I associate each employee with its own
ListConverter object (with different salaries) ? Say for instance I
wanted to have different salary ranges for each position (Director,
Manager etc).
public class ListConverter : StringConverter
{
public override bool
GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection
GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(new string[]
{ "£20,000", "£25,000", "£30,000", "£35,000", "£40,000" });
}
public override bool
GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
}
Appreciate any help.
Trying to get an handle on the property grid which I'm finding very
handy.
I got one problem though that I have not been able to fix.
Here is a small example to illustrate the problem;
Say I want to display a list of employee's with their Name, Position
and Salary in a propertygrid. So far so good.
public class Employee
{
private string _Name = "";
private string _Position = "";
private int _Salary = "";
[DisplayNameAttribute("Employee Name")]
public string Name
{
get { return _Name}
set { _Name= value; }
}
[DisplayNameAttribute("Employee Position),
DescriptionAttribute("TODO")]
public string Position
{
get { return _Position}
set { _Position= value; }
}
[TypeConverter(typeof(ListConverter)),
DisplayNameAttribute("Employee Salary"), DescriptionAttribute("TODO")]
public int Salary
{
get { return _Salary}
set { _Salary= value; }
}
}
By adding a ListConverter I'm able to get a drop down list of all the
options available. However, the same list would apply for all
employees. How can I associate each employee with its own
ListConverter object (with different salaries) ? Say for instance I
wanted to have different salary ranges for each position (Director,
Manager etc).
public class ListConverter : StringConverter
{
public override bool
GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection
GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(new string[]
{ "£20,000", "£25,000", "£30,000", "£35,000", "£40,000" });
}
public override bool
GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
}
Appreciate any help.