how to set default values for non-basic type properties?

Discussion in 'ASP .Net Building Controls' started by Ben Schwehn, Sep 21, 2003.

  1. Ben Schwehn

    Ben Schwehn Guest

    Hello everyone.

    I need some help with how to set default values for 'complex' properties.

    My problem is this:
    I have a control with a property CellStyle of type TableItemStyle. I want
    to initialise this property with some default values eg.
    CellStyle.ForeColor="Gray" etc.

    With a basic datatype i would just use the DefaultValueAttribute eg for a
    bool I'd add the attribute: [DefaultValue(true)] How can i do this for my
    CellStyle property?

    My workaround so far is to just inititialise CellStyle in the
    contstructor, which works to the extend that the values I set in the
    constructor are all displayed in VS, however I would like the IDE to know
    that the values are default values (because the IDE adds all values it
    thinks are not default to the tag definition in the aspx file eg adds
    <CellStyle Font-Size="12px" Height="32px" BackColor="#D6D3CE"></CellStyle>
    to the control tag even though these are the default values).

    Thanks!
    Ben
     
    Ben Schwehn, Sep 21, 2003
    #1
    1. Advertising

  2. "Ben Schwehn" <> wrote in message
    news:p...
    > Hello everyone.
    >
    > I need some help with how to set default values for 'complex' properties.
    >
    > My problem is this:
    > I have a control with a property CellStyle of type TableItemStyle. I want
    > to initialise this property with some default values eg.
    > CellStyle.ForeColor="Gray" etc.
    >
    > With a basic datatype i would just use the DefaultValueAttribute eg for a
    > bool I'd add the attribute: [DefaultValue(true)] How can i do this for my
    > CellStyle property?
    >
    > My workaround so far is to just inititialise CellStyle in the
    > contstructor, which works to the extend that the values I set in the
    > constructor are all displayed in VS, however I would like the IDE to know
    > that the values are default values (because the IDE adds all values it
    > thinks are not default to the tag definition in the aspx file eg adds
    > <CellStyle Font-Size="12px" Height="32px" BackColor="#D6D3CE"></CellStyle>
    > to the control tag even though these are the default values).


    When you add a DefaultValue attribute to a property, it does not initialize
    the property to that value. This attribute simply tells the Property Grid
    which value is the default. All non-default values will be displayed in bold
    type.
    --
    John Saunders
    Internet Engineer
     
    John Saunders, Sep 21, 2003
    #2
    1. Advertising

  3. Ben Schwehn

    Ben Schwehn Guest

    >> My problem is this:
    >> I have a control with a property CellStyle of type TableItemStyle. I want
    >> to initialise this property with some default values eg.
    >> CellStyle.ForeColor="Gray" etc.

    ....

    > When you add a DefaultValue attribute to a property, it does not initialize
    > the property to that value. This attribute simply tells the Property Grid
    > which value is the default. All non-default values will be displayed in bold
    > type.


    Hello John,

    that's right. i should have said

    --
    With a basic datatype i would just use the DefaultValueAttribute eg for a
    bool I'd add the attribute: [DefaultValue(true)] _and_ initialise it to
    true.
    --

    Still, how do i tell the Prooperty Grid which values are default with a
    Property of type TableItemStyle, is it possible at all? I was thinking
    about deriving a type from TableItemStyle that initialises all properties
    to the value i want and then use

    MyOwnTableItemStyle bla = new MyOwnTableItemStyl();

    ....

    DefaultValue(bla)


    not sure whether that would work at all but even if it does it's quite
    messy code i think...


    Cheers
    ben
     
    Ben Schwehn, Sep 22, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. desktop
    Replies:
    2
    Views:
    467
    Victor Bazarov
    Jun 6, 2007
  2. Jonathan Wood
    Replies:
    2
    Views:
    4,280
    Jonathan Wood
    Feb 8, 2008
  3. Praveen Ramesh

    Specifying dynamic default values for properties in custom controls:

    Praveen Ramesh, Sep 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    133
    Praveen Ramesh
    Sep 2, 2004
  4. Christophe Peillet

    CreateChildControls() always has default values for properties

    Christophe Peillet, Jan 14, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    238
    Steven Cheng[MSFT]
    Jan 16, 2006
  5. Kilo

    Non Default Properties

    Kilo, Oct 11, 2008, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    765
Loading...

Share This Page