473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Defaultvalue

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.

Feb 16 '07 #1
2 1889
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.?

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"RedLars" wrote:
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.

Feb 16 '07 #2
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).
On 16 Feb, 13:20, Ciaran O''Donnell
<CiaranODonn...@discussions.microsoft.comwrote:
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.?

--
Ciaran O''Donnellhttp://wannabedeveloper.spaces.live.com
Feb 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Maurice Mertens | last post by:
Hi, I have an Access database in which I defined default values for certain columns. On my windows forms I've got controls bound to the dataset, The problem is that when I add a new row to the...
0
by: Craig Schneider | last post by:
// Is there any way to override the XML Serialization of the following SimpleClass // to turn off the DefaultValue of a boolean? Sure, I can override the DefaultValue from // true to false, but...
1
by: Mark | last post by:
How do I write the following code to set the default value? Me!xNum.DefaultValue = Me!XCurrency.DefaultValue = Me!XDate.DefaultValue = Me!XString.DefaultValue = Can I just put all the lines...
2
by: timtos | last post by:
I want to set a color property of a user control by default. I am doing it like this: .... DefaultValue(typeof(System.Drawing.Color), "Blue"), .... The compiler likes it but my program...
3
by: MLH | last post by:
On frmVehicleEntryForm... I wanted to change the DefaultValue property of one of my textbox controls on a form from within code. I wanted the setting to be no setting - as if nothing had ever...
0
by: Shadow Lynx | last post by:
Language: VB.Net 2.0 (Windows Application) IDE: MS VB 2005 Exp. Ed. Summary: Setting a DefaultValue of type Decimal for the Property of a UserControl does not work properly - the value appears...
10
by: tony | last post by:
Hello!! I have some demo programs written in C# and they have this construction "" see below. I haven't seen this before so what does it mean ? public bool ShowDropDownButtons { get {...
6
by: Peter Hartlén | last post by:
Hi! What's the correct syntax for the default value design time attribute, using classdiagram view and Custom Attributes dialog. For a boolean: DefaultValue(true) DefaultValue("true")...
3
by: Johnny Jörgensen | last post by:
Does anybody know how to correctly specify the defaultvalue attribute for a property whose type is an enum. Example: Public Enum TestValues Value1=1 Value2=2 End Enum
25
by: kstevens | last post by:
I have a sub to determine if overtime has come into play yet on a certain job. If (preapproved) overtime has started then the next (subform) record can automatically be populated from a query...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.