Defaultvalue

R

RedLars

This code set an employee's salary to £20,000 by default. I'd like to
set this at runtime, i.e. let the variable _recommendSalary be the
default value.

public class Employee
{
private string _Name = "";
private int age = 0;
private string _Position = "";
private string _Salary = "";
private string _recommendSalary = "£22,000";
private string[] _SalaryOption = { "£20,000", "£25,000",
"£30,000", "£40,000" };

[DefaultValueAttribute("£20,000")]
public string Salary { ... }
// properties to access member values
}

Been looking at this for a while but unsure which method that would
handle such a property. I have both an EmployeeCollection class that
implements ICustomTypeDescriptor and
EmployeeCollectionPropertyDescriptor that inherets from
PropertyDescriptor.

Appreciate any input.
 
G

Guest

This is not possible as the attribtue is compiled into the metadata for the
assembly and it cannot be modified at runtime.

Is this just to get the property grid value to not be bold when the value
isnt 20K.?
 
R

RedLars

Thanks for the feedback.

Very surprised by this. I'm about to design a configuration tool which
fits in with the property grid. My aim is to differentiation between a
default value and other values (not wether the text is bold or not).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top