From: Michel Racicot on
Far more easy to understand ;)

I've added a string property (named "TokenType" to the custom combobox...
dropped the customcombo on a form and set the new property in the property
inspector in design time.

But if I try to access the value in the constructor of the ComboBox (to load
its value), it's not set! The string is empty... So I can't use it to load
the combo correctly.

"Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
news:OuUx7vz4KHA.3880(a)TK2MSFTNGP04.phx.gbl...
> On 4/23/2010 6:10 PM, Michel Racicot wrote:
>> The problem is that my custom property isn't set yet in the
>> constructor.... I don't understand why...
>>
>
> Can you explain what that means? Do you mean that you need a property to
> be set "within" the constructor, so that you need a non-parameterless (if
> that is a word) constructor, something like below? I don't think this is
> possible for a control given that a user may drop it onto a form.
>
> public class MyComboBox : ComboBox
> {
> public string ConnectionString {get; set;}
> public MyComboBox (string connectionstring)
> {
> ConnectionString = connectionstring;
> // open a dataset, for example...
> }
> }
>
> --
> Mike

From: Michel Racicot on
Obviously, from the code in the designer of the form, the constructors of
child controls are called before setting the properties... That makes sense.

But I need an event that will be called after the properties are set... like
a custom "OnLoad" event.

"Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
news:OuUx7vz4KHA.3880(a)TK2MSFTNGP04.phx.gbl...
> On 4/23/2010 6:10 PM, Michel Racicot wrote:
>> The problem is that my custom property isn't set yet in the
>> constructor.... I don't understand why...
>>
>
> Can you explain what that means? Do you mean that you need a property to
> be set "within" the constructor, so that you need a non-parameterless (if
> that is a word) constructor, something like below? I don't think this is
> possible for a control given that a user may drop it onto a form.
>
> public class MyComboBox : ComboBox
> {
> public string ConnectionString {get; set;}
> public MyComboBox (string connectionstring)
> {
> ConnectionString = connectionstring;
> // open a dataset, for example...
> }
> }
>
> --
> Mike

From: Michel Racicot on
And the Layout event seems to be called too often to my taste.

"Michel Racicot" <mracicot(a)hotmail.com> wrote in message
news:uJx3w6z4KHA.1932(a)TK2MSFTNGP05.phx.gbl...
> Far more easy to understand ;)
>
> I've added a string property (named "TokenType" to the custom combobox...
> dropped the customcombo on a form and set the new property in the property
> inspector in design time.
>
> But if I try to access the value in the constructor of the ComboBox (to
> load its value), it's not set! The string is empty... So I can't use it
> to load the combo correctly.
>
> "Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
> news:OuUx7vz4KHA.3880(a)TK2MSFTNGP04.phx.gbl...
>> On 4/23/2010 6:10 PM, Michel Racicot wrote:
>>> The problem is that my custom property isn't set yet in the
>>> constructor.... I don't understand why...
>>>
>>
>> Can you explain what that means? Do you mean that you need a property to
>> be set "within" the constructor, so that you need a non-parameterless (if
>> that is a word) constructor, something like below? I don't think this is
>> possible for a control given that a user may drop it onto a form.
>>
>> public class MyComboBox : ComboBox
>> {
>> public string ConnectionString {get; set;}
>> public MyComboBox (string connectionstring)
>> {
>> ConnectionString = connectionstring;
>> // open a dataset, for example...
>> }
>> }
>>
>> --
>> Mike
>
From: Family Tree Mike on
On 4/23/2010 7:46 PM, Michel Racicot wrote:
> Obviously, from the code in the designer of the form, the constructors
> of child controls are called before setting the properties... That makes
> sense.
>
> But I need an event that will be called after the properties are set...
> like a custom "OnLoad" event.
>

Assuming you want to fill the combobox items when the property changes,
in the designer or at runtime, then I would code it like this:

public class MyComboBox : ComboBox
{
string _TokenType;
public string TokenType
{
get { return _TokenType; }
set
{
_TokenType = value;
Items.Clear();
Items.Add(TokenType);
SelectedIndex = 0;
}
}
}


--
Mike
First  |  Prev  | 
Pages: 1 2
Prev: Need Linq Help
Next: Communicating with a Unix server