473,569 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TreeView node style - for an individual node

Hi all,

I just went over a *lot* of tree node style properties (LeftNodeStyle,
NodeStyle, ParentNodeStyle , RootNodeStyle, LevelStyles, HoverNodeStyle,
SelectedNodeSty le, 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.ChildN odes.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.
Jul 23 '07 #1
5 15640
I think the CssClass property is the [Something] you are looking for.

--code--
if (...) {
tnNewNode = new TreeNode(strCap tion);
tnNewNode.CssCl ass = "BoldNode";
tnParent.ChildN odes.Add(tnNewN ode);
}

--css--
..MyTreeClass .BoldNode {
font-weight:bold;
}
"Homer J. Simpson" <ro**@127.0.0.1 wrote in message
news:e1******** *****@TK2MSFTNG P05.phx.gbl...
Hi all,

I just went over a *lot* of tree node style properties (LeftNodeStyle,
NodeStyle, ParentNodeStyle , RootNodeStyle, LevelStyles, HoverNodeStyle,
SelectedNodeSty le, 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.ChildN odes.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.
Jul 23 '07 #2
I think the CssClass property is the [Something] you are looking for.
>>
--code--
if (...) {
tnNewNode = new TreeNode(strCap tion);
tnNewNode.CssCl ass = "BoldNode";
tnParent.ChildN odes.Add(tnNewN ode);
}

--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.
Jul 24 '07 #3
>I think the CssClass property is the [Something] you are looking for.
>
--code--
if (...) {
tnNewNode = new TreeNode(strCap tion);
tnNewNode.CssCl ass = "BoldNode";
tnParent.ChildN odes.Add(tnNewN ode);
}

--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).
Jul 24 '07 #4
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" <ro**@127.0.0.1 wrote in message
news:ek******** ******@TK2MSFTN GP03.phx.gbl...
>I think the CssClass property is the [Something] you are looking for.

--code--
if (...) {
tnNewNode = new TreeNode(strCap tion);
tnNewNode.CssCl ass = "BoldNode";
tnParent.ChildN odes.Add(tnNewN ode);
}

--css--
.MyTreeClas s .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.
Jul 24 '07 #5
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.
Jul 24 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3364
by: mike uk | last post by:
I'm generating a treeview (in asp.net Page_Load event) by adding nodes to a treeview control, and then selecting a single node in the tree using node.Select(). EnableClientScript property is set to true, which prevents any autopostbacks. EnableViewState property is set to false, since I'm not interested in postbacks. The treeview...
2
1812
by: Sam | last post by:
Hi, Say I have the following Treeview : N1 |-N11 |-N12 |-N121 |-N122 N2 |-N21
2
1388
by: David Thielen | last post by:
Hi; I have a node where it is "<w:t> </w:t>" and what I get from XmlTextReader is Element, SignificantWhitespace, EndElement instead of Element, Text, EndElement. Question 1 is why? The text of that node is a space. Question 2 is how do I handle this. Do I watch for a SignificantWhitespace inside an Element/EndElement? Or will that get...
0
1390
by: michael.neel | last post by:
How do you set a node's style (font, css class, etc) dynamically? This seemed like it would be simple, but I cannot find an event, method, or property of a node available at run time that contains the style information. What I want to do is simply set the css class to "active" for the active node and any parent nodes, excluding the root...
1
1067
by: sethuganesh | last post by:
Hi, i want to know how to create a xml file having nodes with same name.how to identify the node with unique id. will it create a new node with same node name that have already created?
0
1299
by: jonny | last post by:
Hi, I have a template "delete-node" with two arguments containing document fragments when called. I want to return a new document fragment which contains all nodes from argument 2 except the one which is contained in argument 1. The code currently looks like this:
1
1942
by: Tedros.G | last post by:
Hi I have an attribute the appears in both the root node and child node for example, below the attribute VERSION appears in the rood node (PRODMSG ) and a child node (OPERATION ) ================ INPUT XML ================ <?xml version="1.0" encoding="utf-16"?> <PRODMSG VERSION="1.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
6
11945
by: xla76 | last post by:
I have a simple treeview (treeview1) to which I have added two nodes (nodeA and nodeB) which have n levels of child nodes. What I want is to be able to identify whether the child node I select is under NodeA or NodeB. I can do this by splitting the selectednode.fullpath of the child node but there must be a better way. Can any kind soul...
4
2117
by: remlostime | last post by:
now, I define the struct following: struct node { bool match; node* child; }; What's the difference between 1) node *Trie=new node(); and 2) node *Trie = new node;
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.