473,472 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Default values and form inheritace

I am trying to create a control, using standard user components A.
The I use that component A as part of a new component B.
And finally I drop that component B on my form.

Now in Component A I filled in some default fields like this.

[Browsable(true)]
[DefaultValue("Title"), Category("Appearance")]
override public System.String Text {
set {
Title.Text=value;
Title.Invalidate(true);}
get {return Title.Text;}
}

So on the Component B I changed the "Title" to something else (in this case
X-Axis) using the property editor, this works nice.

But when I run the program then the original Title is put there while then
it should be the "X-Axis"

Has anyone have experience with this?
Did I miss something? Some initialization order?
Currently I solve the problem by forcing it in the main form
programatically.


Nov 17 '05 #1
4 1245
Hi Olaf,
if i understand what you trying , since the control B derrives from control
A, when you put the control B in a form it overrides the B.Text in the
InitializeComponents () function. try to set the Text property of the
control B in your form from the property Window to "", this will delete the
line B.Text = "B"; from the InitializeComponents () function and will have
the default value of the A control.
If that works tel me about it cos i haven try it.
"Olaf Baeyens" <ol**********@skyscan.be> wrote in message
news:42*********************@news.skynet.be...
I am trying to create a control, using standard user components A.
The I use that component A as part of a new component B.
And finally I drop that component B on my form.

Now in Component A I filled in some default fields like this.

[Browsable(true)]
[DefaultValue("Title"), Category("Appearance")]
override public System.String Text {
set {
Title.Text=value;
Title.Invalidate(true);}
get {return Title.Text;}
}

So on the Component B I changed the "Title" to something else (in this
case
X-Axis) using the property editor, this works nice.

But when I run the program then the original Title is put there while then
it should be the "X-Axis"

Has anyone have experience with this?
Did I miss something? Some initialization order?
Currently I solve the problem by forcing it in the main form
programatically.



Nov 17 '05 #2
> if i understand what you trying , since the control B derrives from
control
A, when you put the control B in a form it overrides the B.Text in the
InitializeComponents () function. try to set the Text property of the
control B in your form from the property Window to "", this will delete the line B.Text = "B"; from the InitializeComponents () function and will have
the default value of the A control.
If that works tel me about it cos i haven try it.

I think that is what I tried to explain.
But on the web I found some examples how to fix this. Only the big trouble
is that it is very hard to understand what they try to explain, so when I
have a workable solution then I will post ik back.

Nov 17 '05 #3
I think I start to understand what is going on.
Maybe my explanation was not that good.

I have a user control A that contains a,b,c
I fill in a.Text="text" in the property editor.

Now I create a control B, that contains 2 A controls.
And I change the a.Text of control A on the B control using the property
editor to "Test 2"

I keep the control B visible on screen and recompile and wonder over wonder
the string "Test 2" gets replaced by to older "text".
So my executable incorrecly shows the older "text" string instead of the new
"Test 2".

But when I add this:

private void B_Load(object sender, System.EventArgs e) {
A.Text="Test 2";
}

The the label is correctly shown, but is a hack since it overrides the
property editor's choice programatically.

My guess is that B instantiates A, and any value given in B is overridden by
the fact that A gets instantiated later.
Is there a good trechnique for fixing this?
Nov 17 '05 #4
Odd I open the B control in design view.
I select the first A control, and in the property editor I change the "Text"
property to another string.
I see visually that the B control has the new updated text, and the property
editor also shows the text.
I save all files.

I close the B control dialog box.
Open it again and the original text is back, not the one I edited.

If I look inside the genarated B.cs code then I do not see the A.Text
property initialized in the "private void InitializeComponent()" part of
control B.cs.

It could because I created my own text property for A. (because A is
composed of 3 standard controls and one of it is a label, that shows that
A.Text string.

This is the definition of that A.Text property, is something missing?

private System.Windows.Forms.Label Title;

[Browsable(true)]
[DefaultValue("Title"), Category("Appearance")]
[Description("The title")]
override public System.String Text {
set {
Title.Text=value;
Title.Invalidate(true);
}
get {return Title.Text;}
}


Nov 17 '05 #5

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

Similar topics

2
by: Todd D. Levy | last post by:
I have a table of Country names & Country codes in alphabetical order. This is a lookup table that a number of other tables use to populate the Country field via a drop down Combo Box on the...
2
by: jerome g | last post by:
Hi, I'm trying to use a (simple) form to create a new record, with all values being default values coming from a previous form. My problem is that I can save that new record only if I change one...
3
by: countd4 | last post by:
I have built a working user control. However, to make it work, I always have to set certian properties using the properties sheet for the control when using it on other forms. I want to be able to...
2
by: Viorel | last post by:
Adding new row with default values. In order to insert programmatically a new row into a database table, without direct "INSERT INTO" SQL statement, I use the well-known DataTable.NewRow,...
7
by: Aaron Smith | last post by:
How do I set field default values at runtime? Say I want a check box that is bound to a boolean field to default to false for a certain set of criteria, and then true for others? I also need to do...
3
by: Charlie | last post by:
Imagine I subclass Panel into MyPanel and set a few property values to my own defaults as shown below. Eg. I set BackColor to by LightYellow. When I add MyPanel to a form, it will write the...
4
by: helenwheelss | last post by:
Access 2003, using a bound form. I'm seeing rather annoying behaviour when editing data in a control with a default value. It only happens when the form is on a new record. A specific...
4
by: Whasigga | last post by:
Hi I've created a form that has 7 subforms. It is the same subform, bound to a table, just repeated. This form represents a week, and each subform is used to enter in data for each day of the...
8
by: peterkennett | last post by:
I am designing a database that will be used by many different offices, and each office may want to change the defaults I have in a table. Rather than teach each user how to go in and change a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.