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. Advertisements

  2. 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, Sep 21, 2003
    #2
    1. Advertisements

  3. Ben Schwehn

    Ben Schwehn Guest

    My problem is this:
    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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.