473,795 Members | 3,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

property with defalut value will not be called in auto-generated code, and how to make a property only visible at design time?

Hi,

What is the best practise to sove this problem:

property with defalut value will not be called in auto-generated code

?

for example

there is a property in a user control

private bool normalMode = false;
public bool NormalMode
{
get
{
return this.normalMode ;
}
set
{
SetAsNormal(val ue);
this.normalMode = value;
}

If I put this user control in a form, in forms InitializeCompo nent(), there
is no code like
userControl1.No rmalMode = false;

so line like SetAsNormal(val ue); will not be called.

What is the best way to solve this? And how to make a property only visible
at design time?

Thanks a lot!
Ryan Liu
Aug 27 '06 #1
2 2215
Re the default value, I would simply ensure that this code gets called
in the ctor.

Re the design time... pass.

Marc

Aug 27 '06 #2
Ryan,

The only way that this will get called is if you have a value that is
different from the default value. You need to do this:

private bool normalMode = false;

[DefaultValue(fa lse)];
public bool NormalMode
{
get
{
return this.normalMode ;
}
set
{
SetAsNormal(val ue);
this.normalMode = value;
}
}

Then, the designer will set the value for your component in
InitializeCompo nent method when you set a value to something OTHER than the
default value. If it is NOT the default value, then it ^will^ not and
^should^ not be set.

If you have a need for SetAsNormal(val ue) to be called, then in your
constructor, you should call SetAsNormal(nor malMode).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Ryan Liu" <ad********@onl ine.sh.cnwrote in message
news:ec******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

What is the best practise to sove this problem:

property with defalut value will not be called in auto-generated code

?

for example

there is a property in a user control

private bool normalMode = false;
public bool NormalMode
{
get
{
return this.normalMode ;
}
set
{
SetAsNormal(val ue);
this.normalMode = value;
}

If I put this user control in a form, in forms InitializeCompo nent(),
there
is no code like
userControl1.No rmalMode = false;

so line like SetAsNormal(val ue); will not be called.

What is the best way to solve this? And how to make a property only
visible
at design time?

Thanks a lot!
Ryan Liu


Aug 27 '06 #3

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

Similar topics

4
2410
by: spar | last post by:
I'm converting a Perl script to Python and have run into something I'm not sure how to do in Python. In Perl, I am running through a couple loops and inserting values directly into a complex data structure (array->hash->array). This isn't the actual code, but should demonstrate the general idea: foreach $bar_count(@bars) { foreach $el_count(@els) { $var = somefunc($bar_count,$el_count);
31
3114
by: Chris Stanley | last post by:
I am using dreamweaver to make an ASP page. I have a table of data from a MSSQL database that is currently showing on the ASP page. I want the ability to change the color based on a priority number that's in the MSSQL database (same recordset that the data comes from). I don't have the priority field out on the page but can put it out if need be. I have 3 different priority numbers and if the first row is priority 1 I want the font to...
0
1419
by: amywolfie | last post by:
Hi all: I have a subform called sfrmFootnotes linked to main Form frmFeeInput (the latter based on tblFees). tlkpFootnotes contains the PK for Footnotes. tjnCode_Footnotes is a join table between tlkpFootnotes and tblFees which contains FK_Code & FK_Footnotes [unique Index set for these 2 fields).
8
14009
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on stack. this contains the arguments this function was called with, address to return to after return from this function (the location in the previous stack frame), location of previous frame on stack (base or start of this frame) and local variables...
20
3615
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this exit(n)) statement provide both function call and return features of the C programming language? /* headers omitted */ int main (void)
5
3278
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if I change 'auto' to 0 for left and right margin values; I have to leave those at 'auto'.. so I would like to know what exactly means 'auto' -- what value it represents exactly (and does it apply for all elements/values you might apply 'auto' to?)
2
2365
nev
by: nev | last post by:
i place values in a new row programatically. it has an auto-increment column. after adding the entries i do... bindingsource.endedit() tableadapter.update(dataset.datatable) the saving process has no problem. now, i want to get the value of the new record's auto-increment column. if i do this... textbox.text = directcast(bindingsource.current,datarowview)("Auto") it will generate an error, nullreferenceexception was unhandled,...
2
1456
by: DAHMB | last post by:
I Have a form that I use to launch a report from. In the form I have two hidden text boxes that are date fields called fiscal1 and fiscal2. Fiscal1 has a default value of 7/1/2007 Fiscal2 has a default value of 6/30/2008 Is there a way to have these two fields automatically change each year. Such as on July 1 2008 I want Fiscal1 to change to 7/1/2008 annd Fiscal2 to change to 6/30/2009. Thanks Dan
6
3540
by: gurge | last post by:
Hello! I have a form in datasheet view with checkboxes. One of them is called Cancelled. In the SQL table it is a bit value. When a user keys in a line, the checkbox should be default unchecked unless he/she checks it. So what I have done is to set the default value to False (have tried 0 as well) and in the bottom row (the add new line row) this box is shown to be unchecked. But once I key in any data in the row, the checkbox...
176
9204
by: MNNovice | last post by:
I have developed a database for my CD collections. I am trying to develop serial number of each CD which will populate based on data entered in a form called frmCDDetails. This form is based on a table called tblCDDetails which combines data from various tables. Table 1 tblMusicCategory Field 1: MusicCategoryID - Auto Number (Primary) Field 2: MusicCategory - text Field 3: MusicCategoryAbbv - text Each category is uniquely given...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9042
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.