Grey is not Gray or How to customize the styles on individual TreeNodes

January 4, 2006

On the standard TreeView of ASP.NET 2.0 it is not possible to give individual TreeNodes different styles. With the style attributes on the TreeView, one can only set the styling for a certain group of nodes, like the styling for all the leafnodes with the LeafNodeStyle attribute. However, it is possible to add styling on individual nodes with just a few lines of code. Just create a custom treenode class by inheriting from TreeNode, add some styling attributes and apply these attributes to the node by overriding the RenderPreText method.

You can see some code on how to do this on the ASP.NET forums and in the comments on a post of Danny Chen . Just check it out. Done ? Ok ! As you can see, while trying out this solution I made the mistake of writing ‘Gray’ as ‘Grey’ which lead me to some funny conclusions about why it wasn’t working. Guess it is better to think twice before posting or to have a spellchecker in Visual Studio. 🙂

Update : Kris van der Mast, probably by far Belgium’s most active poster on the ASP.NET forums, pointed me to a blogentry of Fredrik NormĂ©n, dated even before Beta2 was released, that already talked about this extensibility of TreeNodes.

Advertisements

One Response to “Grey is not Gray or How to customize the styles on individual TreeNodes”

  1. treasury Says:

    It is widespread thing to encounter some sorts of illnesses within our life,
    but the factor is it really is uncommon to meet the proper treatment as
    soon as. Go here to instantly download Yeast Infection No More Book What precisely makes Yeast Infection No More Book unique is the degree of focus that is given to each and every aspect needed to attain
    permanent escape from candidiasis linked symptoms. Also like many
    single parents, Sebastiao is hoping to share the bills with her former spouse.
    If you suspect that your method has become
    infected there are a number of points you can do yourself to try to
    get rid of the offending application. The doctor will ask about symptoms of metabolic disorders such as fatigue, headaches, cramping, mood changes, shortness of breath, and chronic
    diarrhea.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: