Setting default values to datagrid headerstyle

J

Joey Lee

Hi,

How do one set default value for objects?

For simple attributes like string, one can do it like

[Bindable(true),
Category("Appearance"),
DefaultValue("datagridstyle")]
public override string CssClass
{
get
{
return base.CssClass;
}
set
{
base.CssClass = value;
}
}

but for headerstyle-CssClass, how do one go about? I want to change the
CssClass value only. If i create a TableItemStyle, where should i code this
and how do i assign it to the defaultValue part?

[DefaultValue("???")]
public override TableItemStyle HeaderStyle
{
get
{
return base.HeaderStyle;
}
}


Or have i make mistake... and there are better way of doing this?

Thanks

Joey
 
M

Matt

The DefaultValue attribute doesn't actually set the default value ...
it just tells the designer what to expect as the default value ... You
can set your default values like you would in any other class using
initializers:

private MyEnum _MyEnumVal = MyEnum.NotSet;

[DefaultValue(MyEnum.NotSet)]
public MyEnum MyEnumVal {
get {
return this._MyEnumVal;
}
set {
this._MyEnum = value;
}
}

In your examples, since you were wrapping access to the base class'
Members ... the default values were getting set by the base class ...
not your DefaultValue declaration.
 
J

Joey Lee

Thanks.

So is there anyway of setting the designer value and allowing changes later
on?

Joey
 
M

Matt

As long as you have told the designer(Visual Studio) how to persist the
value in code ... the initial value will get over-written by the new,
different value you chose using the designer ... below is the property
ShowHeader from my DataGridPager control ... below
that is the tag from the page showing the non-default value I selected
in Visual Studio persisted in code by a tag attribute

[Category("Appearance"), Description("Show header text."),
DefaultValue(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
PersistenceMode(PersistenceMode.Attribute)]
public bool ShowHeader {
get {
if (this.ViewState["ShowHeader"] == null) {
return true; //Default value
} else {
return (bool)this.ViewState["ShowHeader"];
}
}
set {
this.ViewState["ShowHeader"] = value;
}
}

<cc2:DataGridPager id=DataGridPager2 runat="server"
DataGridToNavigate="dgLicensedVehicles" Font-Size="14px"
ShowHeader="False"></cc2:DataGridPager>
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top