Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > TreeView node style - for an individual node

Reply
Thread Tools

TreeView node style - for an individual node

 
 
Homer J. Simpson
Guest
Posts: n/a
 
      07-23-2007
Hi all,

I just went over a *lot* of tree node style properties (LeftNodeStyle,
NodeStyle, ParentNodeStyle, RootNodeStyle, LevelStyles, HoverNodeStyle,
SelectedNodeStyle, etc etc etc) but can't find exactly what I want.

It seems that I'm in a situation where none of these predefined groups fit
the bill. Ultimately, the style to use needs to be decided as I'm
dynamically adding individual nodes through code. I'd like to do this:

if( [some convoluted conditions] ) {
tnNewNode = new TreeNode( strCaption );
tnNewNode.[Something] = "bold";
tnParent.ChildNodes.Add( tnNewNode );
}

It's this [Something] property that I'm looking for--one that applies to an
individual node, but not necessarily others that happen to fall in some
common category.

I've managed to add separate styles for clickable nodes by using something
like:

..MyTreeClass a
{
(styles that apply to all clickable nodes, which all happen to have an
archor tag)
}

....but I need finer granularity. Thinking along the same way, I've hacked
together the following:

tnNewNode = new TreeNode( "<div class='clsTest'>" + strCaption + "</div>" );

and in my .css file:

..MyTreeClass .clsTest
{
font-weight: bold;
}

But this is *so* ugly I can't help but think there's just gotta be some
better way to do this than force my own div around the node's text.


 
Reply With Quote
 
 
 
 
Brandon Gano
Guest
Posts: n/a
 
      07-23-2007
I think the CssClass property is the [Something] you are looking for.

--code--
if (...) {
tnNewNode = new TreeNode(strCaption);
tnNewNode.CssClass = "BoldNode";
tnParent.ChildNodes.Add(tnNewNode);
}

--css--
..MyTreeClass .BoldNode {
font-weight:bold;
}


"Homer J. Simpson" <root@127.0.0.1> wrote in message
news:...
> Hi all,
>
> I just went over a *lot* of tree node style properties (LeftNodeStyle,
> NodeStyle, ParentNodeStyle, RootNodeStyle, LevelStyles, HoverNodeStyle,
> SelectedNodeStyle, etc etc etc) but can't find exactly what I want.
>
> It seems that I'm in a situation where none of these predefined groups fit
> the bill. Ultimately, the style to use needs to be decided as I'm
> dynamically adding individual nodes through code. I'd like to do this:
>
> if( [some convoluted conditions] ) {
> tnNewNode = new TreeNode( strCaption );
> tnNewNode.[Something] = "bold";
> tnParent.ChildNodes.Add( tnNewNode );
> }
>
> It's this [Something] property that I'm looking for--one that applies to
> an individual node, but not necessarily others that happen to fall in some
> common category.
>
> I've managed to add separate styles for clickable nodes by using something
> like:
>
> .MyTreeClass a
> {
> (styles that apply to all clickable nodes, which all happen to have an
> archor tag)
> }
>
> ...but I need finer granularity. Thinking along the same way, I've hacked
> together the following:
>
> tnNewNode = new TreeNode( "<div class='clsTest'>" + strCaption +
> "</div>" );
>
> and in my .css file:
>
> .MyTreeClass .clsTest
> {
> font-weight: bold;
> }
>
> But this is *so* ugly I can't help but think there's just gotta be some
> better way to do this than force my own div around the node's text.
>


 
Reply With Quote
 
 
 
 
Homer J. Simpson
Guest
Posts: n/a
 
      07-24-2007
>I think the CssClass property is the [Something] you are looking for.
>
> --code--
> if (...) {
> tnNewNode = new TreeNode(strCaption);
> tnNewNode.CssClass = "BoldNode";
> tnParent.ChildNodes.Add(tnNewNode);
> }
>
> --css--
> .MyTreeClass .BoldNode {
> font-weight:bold;
> }


I'm gonna have to try it regardless of that IntelliSense is telling me. It
definitely did *not* popup the .CssClass property (that's the first thing I
was looking for).


 
Reply With Quote
 
Homer J. Simpson
Guest
Posts: n/a
 
      07-24-2007
> >I think the CssClass property is the [Something] you are looking for.
>>
>> --code--
>> if (...) {
>> tnNewNode = new TreeNode(strCaption);
>> tnNewNode.CssClass = "BoldNode";
>> tnParent.ChildNodes.Add(tnNewNode);
>> }
>>
>> --css--
>> .MyTreeClass .BoldNode {
>> font-weight:bold;
>> }

>
> I'm gonna have to try it regardless of that IntelliSense is telling me.
> It definitely did *not* popup the .CssClass property (that's the first
> thing I was looking for).


Nope, it doesn't look like .CssClass is a valid property for a TreeNode.
Looking at the raw HTML as received by the browser, each node already has
both an id and a class, so it's not entirely surprising that you can't
specify your own class to override it.


 
Reply With Quote
 
Brandon Gano
Guest
Posts: n/a
 
      07-24-2007
TreeView must have been one of the controls MS threw together at the last
minute. You're right; <asp:TreeNode /> provides no means of specifying
styles. It has no CssClass property and no skinning capabilities. I think
the best you can get without some serious work on the Render methods of
these controls is to style the nodes based on their heirarchical level. For
example:

--aspx--
<asp:TreeView CssClass="tree" ID="MyTree" runat="server">
<Nodes>
<asp:TreeNode Text="Red">
<asp:TreeNode Text="Green">
<asp:TreeNode Text="Blue" />
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>

--css--
.tree a { color:red; }
.tree div a { color:green; }
.tree div div a { color:blue; }


"Homer J. Simpson" <root@127.0.0.1> wrote in message
news:...
>> >I think the CssClass property is the [Something] you are looking for.
>>>
>>> --code--
>>> if (...) {
>>> tnNewNode = new TreeNode(strCaption);
>>> tnNewNode.CssClass = "BoldNode";
>>> tnParent.ChildNodes.Add(tnNewNode);
>>> }
>>>
>>> --css--
>>> .MyTreeClass .BoldNode {
>>> font-weight:bold;
>>> }

>>
>> I'm gonna have to try it regardless of that IntelliSense is telling me.
>> It definitely did *not* popup the .CssClass property (that's the first
>> thing I was looking for).

>
> Nope, it doesn't look like .CssClass is a valid property for a TreeNode.
> Looking at the raw HTML as received by the browser, each node already has
> both an id and a class, so it's not entirely surprising that you can't
> specify your own class to override it.
>


 
Reply With Quote
 
Homer J. Simpson
Guest
Posts: n/a
 
      07-24-2007
> TreeView must have been one of the controls MS threw together at the last
> minute. You're right; <asp:TreeNode /> provides no means of specifying
> styles. It has no CssClass property and no skinning capabilities. I think
> the best you can get without some serious work on the Render methods of
> these controls is to style the nodes based on their heirarchical level.
> For example:
>
> --aspx--
> <asp:TreeView CssClass="tree" ID="MyTree" runat="server">
> <Nodes>
> <asp:TreeNode Text="Red">
> <asp:TreeNode Text="Green">
> <asp:TreeNode Text="Blue" />
> </asp:TreeNode>
> </asp:TreeNode>
> </Nodes>
> </asp:TreeView>
>
> --css--
> .tree a { color:red; }
> .tree div a { color:green; }
> .tree div div a { color:blue; }


I was kinda leaning in that direction, but the problem is that the
conditions that drive the visual rendering in my case isn't easily
represented in CSS. I definitely cannot use the hierarchy level either.
The ideal would be for me to decide the class to use in code, and then
assign the class name to some (apparently missing) node property.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Expand any node then other node collaps using JS - Treeview Contro Manoj ASP .Net 0 11-04-2008 01:35 PM
How to find node in TreeView by using string(the same as Node.Text) ? jiing ASP .Net 0 04-27-2007 02:34 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
ASP.NET 2.0 TreeView - Programatically Selecting A TreeView Node =?Utf-8?B?VHltYm93?= ASP .Net 2 01-10-2006 03:51 AM
How to drag a sub-node to another node in TreeView? wolf ASP .Net 0 08-18-2004 11:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57