User Control Properties
Hi,
I am creating a user control that is derived from the ComboBox control. My problem is that I have added two properties but niether of them are used when set in the designer at runtime.
What am I doing wrong?
The properties are declared in the class like this,
Private bool _test;
public bool Test
{
get{return _test;}
set{_test = value;}
}
[413 byte] By [
jc_walsh] at [2007-11-18 19:01:24]

# 1 Re: User Control Properties
Did you read and follow the instructions in
"Design-Time Attributes for Components"??
# 2 Re: User Control Properties
I have added some of these am I missing one in particular?
this is what I actually have at the moment
private bool _test;
[
Category("Test"),
Description("Test Property")
]
public bool Test
{
get{return _test;}
set{_test = value;}
}
The problem is that I set the value but it is not used in runtime.
# 3 Re: User Control Properties
Where did you set the value?
If you set the value in the "InitializeComponent" method there's a good chance the code will be changed by the designer.
In which case, try setting the value in the constructor.
If that's not it, how are you using the value?
Norfy at 2007-11-9 1:39:35 >

# 4 Re: User Control Properties
Hi,
What exactly do you mean set the values, I set initial values in the code, but change them in the design properties dialog.
Is the problem that I am using the values in the constructor?
Thanks
# 5 Re: User Control Properties
If you change the values at design time, then they should be set in the InitializeComponent method. This you can easily check.
Obviously testing for these values has to be after this method. :)
If you still have a problem it might be an idea to post the code here as an attachment.
Norfy at 2007-11-9 1:41:39 >

# 6 Re: User Control Properties
Here is the code,
It is just a user control that dervies from ComboBox. What I want it to be able to do is display a list of Month/Years. The properties it has are Backwards to allow the Month/Year to be displayed backwards from todays month/year or forwards. You can also set the number of years you want to be displayed.
Thanks for taking a look at the code.
# 7 Re: User Control Properties
As far as I can see there is nothing wrong with the code. If I understand you correctly, you want to be able to set a property at design time that is used to build your component.
The problem is that the designer always uses the default constructor to build a component and then the design properties are applied afterwards. (This is normal) If you look in the InitializeComponent method of your (testing) Form code you'll see what I mean.
What you will need to do is in the property setters add a method which forces your component to rebuild its lists.
public bool Test
{
get{return _test;}
set{
if(test != value)
{
_test = value;
InitializeList();
}
}
Norfy at 2007-11-9 1:43:36 >
