473,686 Members | 3,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET Treeview selectedNodeSty le

Hi,

I use the selectednodesty le with a white background so the user can see
which item was chosen in the treeview navigation.
The nodes have a navigateURL with a target to another frame.
Navigating works with no postback and the style follow the selected node.
When a new child is added to a node there is a button to refresh the node.
This is done by a postback. After this postback the selected node stays
keeps the selected style.

I think it is a bug.
Could I have done something wrong?
Any information is welcome.

Koen
Apr 14 '06 #1
6 11674
Hi,

There is no bug, you missed one line after adding the new node. when you
insert the new node then you make that your selectednode's selected property
is false. Sample code is below:

TreeView1.Selec tedNode.Selecte d = false;

Have a nice work,

Ayta ZAY
Software Engineer

<cy********@nos pam.nospam> wrote in message
news:02******** *************** ***********@mic rosoft.com...
Hi,

I use the selectednodesty le with a white background so the user can see
which item was chosen in the treeview navigation.
The nodes have a navigateURL with a target to another frame.
Navigating works with no postback and the style follow the selected node.
When a new child is added to a node there is a button to refresh the node.
This is done by a postback. After this postback the selected node stays
keeps the selected style.

I think it is a bug.
Could I have done something wrong?
Any information is welcome.

Koen

Apr 14 '06 #2
Hi Koen,

As Aytacozay, this is because the TreeView will always keep the selected
Node's info, so after you add new nodes and refresh the TreeView, have you
also unselected the original selected Node? If not, you need to mark it as
unselected as aytacozay mentioned.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.


Apr 17 '06 #3
Hi,

Thanks for the feedback.
I see the proposed solution as a workaround.
The tree is used as navigation in my project.
The user navigated to a certain item. The main frame is on a page related to
the item. If the user does a refresh on the nagivation, the main frame is on
the same page and it is desirable the tree shows the original selected node
as selected.
However when the user selects a new node the original node stays selected.

A second problem i noticed:
The selected style works well when clicking on the text of the node.
When the user clicks on the image the navigation works but the selected
style stays on the image. It stays on even when chosing a new item.

I know a solution: don't use images

I am convinced if the somebody from the ASP.NET team has a another look at
the code he/she can do improvements.

Koen

"Steven Cheng[MSFT]" wrote:
Hi Koen,

As Aytacozay, this is because the TreeView will always keep the selected
Node's info, so after you add new nodes and refresh the TreeView, have you
also unselected the original selected Node? If not, you need to mark it as
unselected as aytacozay mentioned.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.


Apr 18 '06 #4
Thanks for your response Koen,

Yes, as for the ImageUrl for SelectedNodeSty le, it is an existing known
issue of the TreeView control, the dev team has recorded this for fixing in
future version. also, based on my test, when we use NavigationUrl for
TreeNode to act as hyperlink, the "SelectedNodeCh anged" event won't get
fired for the TreeView which is also a problem. Currently what I have
tried is creating a cutsom Treeview class derived from the existing
Treeview, and I put some additional property to store Navigation Url, thus,
I can make all the Node as normal TreeViewNode(no t hyperlink node) but use
my customTreeNode class, and in the Treeview's selectedNodecha nged event, I
programmaticall y set Node's Url (reset original selectedNode's url) and
register client-script to do the navigation work. e.g:
Here is my custom Treeview and TreeNode's code:

=============== =============== =
namespace ControlLibrary
{
public class CustomTreeView : TreeView
{
protected override TreeNode CreateNode()
{
return new CustomTreeNode( );
}
}
public class CustomTreeNode : TreeNode
{
private string _navurl;
public string NavUrl
{
get
{
return _navurl;
}
set
{
_navurl = value;
}
}

}

}
=============== ============

=========aspx page=========== =
<cc1:CustomTree View ID="TreeView1" runat="server" Target="main"
SelectedNodeSty le-ImageUrl="~/Images/nor.GIF"
OnSelectedNodeC hanged="TreeVie w1_SelectedNode Changed"

<SelectedNodeSt yle ImageUrl="~/Images/nor.GIF"
BackColor="Lime " />

<Nodes>
<cc1:CustomTree Node Text="New Node1" Target="main"
Value="New Node1" NavUrl="http://www.asp.net">
<cc1:CustomTree Node Text="New Node11" Target="main"
Value="New Node11" NavUrl="http://www.asp.net/?id=1"></cc1:CustomTreeN ode>
<cc1:CustomTree Node Text="New Node12" Target="main"
Value="New Node12" NavUrl="http://www.asp.net/?id=2"></cc1:CustomTreeN ode>
</cc1:CustomTreeN ode>
<cc1:CustomTree Node Text="New Node2" Target="main"
Value="New Node2">
<cc1:CustomTree Node Text="New Node21" Target="main"
Value="New Node21"></cc1:CustomTreeN ode>
<cc1:CustomTree Node Text="New Node22" Target="main"
Value="New Node22"></cc1:CustomTreeN ode>
</cc1:CustomTreeN ode>
<cc1:CustomTree Node Text="New Node3" Value="New Node3">
<cc1:CustomTree Node Text="New Node31" Value="New
Node31"></cc1:CustomTreeN ode>
<cc1:CustomTree Node Text="New Node32" Value="New
Node32"></cc1:CustomTreeN ode>
</cc1:CustomTreeN ode>
</Nodes>
<NodeStyle ImageUrl="~/Images/sel.GIF" />
</cc1:CustomTreeV iew>

===========code behind========= ===============

protected void TreeView1_Selec tedNodeChanged( object sender, EventArgs e)
{
string oldvaluepath = TreeView1.Attri butes["oldnodepat h"];

CustomTreeNode oldNode = TreeView1.FindN ode(oldvaluepat h) as
CustomTreeNode;

if (oldNode != null) { oldNode.ImageUr l =
TreeView1.NodeS tyle.ImageUrl; }

TreeView1.Selec tedNode.ImageUr l =
TreeView1.Selec tedNodeStyle.Im ageUrl;
TreeView1.Attri butes["oldnodepat h"] =
TreeView1.Selec tedNode.ValuePa th;
string script = @"<script language='javas cript'>

window.parent.f rames['{0}'].location.href = '{1}';
</script>";
CustomTreeNode node = TreeView1.Selec tedNode as CustomTreeNode;

Page.ClientScri pt.RegisterStar tupScript(this. GetType(),
"TreeView_Selec t_Script",
string.Format(s cript, node.Target, node.NavUrl ));
}
=============== ===============

Yes, this is quite abit complex and not very elegant, however, we're
limited to the existing interfaces.

also, sorry for the inconvenience this brings you.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.




Apr 19 '06 #5
Steven,

Thanks for your effort.
Your solution result in a postback to do the navigation.
I 'll stick with the navigateURL and wait for the fix.

Koen

"Steven Cheng[MSFT]" wrote:
Thanks for your response Koen,

Yes, as for the ImageUrl for SelectedNodeSty le, it is an existing known
issue of the TreeView control, the dev team has recorded this for fixing in
future version. also, based on my test, when we use NavigationUrl for
TreeNode to act as hyperlink, the "SelectedNodeCh anged" event won't get
fired for the TreeView which is also a problem. Currently what I have
tried is creating a cutsom Treeview class derived from the existing
Treeview, and I put some additional property to store Navigation Url, thus,
I can make all the Node as normal TreeViewNode(no t hyperlink node) but use
my customTreeNode class, and in the Treeview's selectedNodecha nged event, I
programmaticall y set Node's Url (reset original selectedNode's url) and
register client-script to do the navigation work. e.g:
Here is my custom Treeview and TreeNode's code:

=============== =============== =
namespace ControlLibrary
{
public class CustomTreeView : TreeView
{
protected override TreeNode CreateNode()
{
return new CustomTreeNode( );
}
}
public class CustomTreeNode : TreeNode
{
private string _navurl;
public string NavUrl
{
get
{
return _navurl;
}
set
{
_navurl = value;
}
}

}

}
=============== ============

=========aspx page=========== =
<cc1:CustomTree View ID="TreeView1" runat="server" Target="main"
SelectedNodeSty le-ImageUrl="~/Images/nor.GIF"
OnSelectedNodeC hanged="TreeVie w1_SelectedNode Changed"
>

<SelectedNodeSt yle ImageUrl="~/Images/nor.GIF"
BackColor="Lime " />

<Nodes>
<cc1:CustomTree Node Text="New Node1" Target="main"
Value="New Node1" NavUrl="http://www.asp.net">
<cc1:CustomTree Node Text="New Node11" Target="main"
Value="New Node11" NavUrl="http://www.asp.net/?id=1"></cc1:CustomTreeN ode>
<cc1:CustomTree Node Text="New Node12" Target="main"
Value="New Node12" NavUrl="http://www.asp.net/?id=2"></cc1:CustomTreeN ode>
</cc1:CustomTreeN ode>
<cc1:CustomTree Node Text="New Node2" Target="main"
Value="New Node2">
<cc1:CustomTree Node Text="New Node21" Target="main"
Value="New Node21"></cc1:CustomTreeN ode>
<cc1:CustomTree Node Text="New Node22" Target="main"
Value="New Node22"></cc1:CustomTreeN ode>
</cc1:CustomTreeN ode>
<cc1:CustomTree Node Text="New Node3" Value="New Node3">
<cc1:CustomTree Node Text="New Node31" Value="New
Node31"></cc1:CustomTreeN ode>
<cc1:CustomTree Node Text="New Node32" Value="New
Node32"></cc1:CustomTreeN ode>
</cc1:CustomTreeN ode>
</Nodes>
<NodeStyle ImageUrl="~/Images/sel.GIF" />
</cc1:CustomTreeV iew>

===========code behind========= ===============

protected void TreeView1_Selec tedNodeChanged( object sender, EventArgs e)
{
string oldvaluepath = TreeView1.Attri butes["oldnodepat h"];

CustomTreeNode oldNode = TreeView1.FindN ode(oldvaluepat h) as
CustomTreeNode;

if (oldNode != null) { oldNode.ImageUr l =
TreeView1.NodeS tyle.ImageUrl; }

TreeView1.Selec tedNode.ImageUr l =
TreeView1.Selec tedNodeStyle.Im ageUrl;
TreeView1.Attri butes["oldnodepat h"] =
TreeView1.Selec tedNode.ValuePa th;
string script = @"<script language='javas cript'>

window.parent.f rames['{0}'].location.href = '{1}';
</script>";
CustomTreeNode node = TreeView1.Selec tedNode as CustomTreeNode;

Page.ClientScri pt.RegisterStar tupScript(this. GetType(),
"TreeView_Selec t_Script",
string.Format(s cript, node.Target, node.NavUrl ));
}
=============== ===============

Yes, this is quite abit complex and not very elegant, however, we're
limited to the existing interfaces.

also, sorry for the inconvenience this brings you.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.




Apr 19 '06 #6
Thanks for the followup.

I agree and understand your consideration. Anyway, please feel free to post
here if there is anything else we can help.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Apr 19 '06 #7

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

Similar topics

3
2164
by: Peter | last post by:
Hello Thanks for reviewing my question. I would like to know how can I programmatically select a node Thanks in Advanc Peter
5
9490
by: Dotnet Gruven | last post by:
With this TreeView declaration: <asp:TreeView ID="Cloner" runat="server" SelectedNodeStyle-Font-Bold="true" SelectedNodeStyle-ForeColor="#003E21" OnTreeNodePopulate="PopulateNode" OnSelectedNodeChanged="SelectNode" ExpandDepth="0">
0
1373
by: AcuZod | last post by:
Heyas! Using the TreeView control on a website built in VS 2005, the SelectedNodeStyle.ImgURL setting doesn't seem to work. Here are my settings: ImgSet = "Custom" NodeStyle.ImgURL = 'image1.gif" NodeStyle.ForeColor = "Black" SelectedNodeStyle.ImgURL = 'image2.gif" SelectedNodeStyle.ForeColor = "Blue"
0
1485
by: sunny076 | last post by:
Hi, In my application, I use treeview inside a frame so when a tree node is clicked, it will direct to the main content only. I have set the selectednodeStyle with BackColor="Yellow", but when I selected the first node and then sleect another the back color is still yellow for the former one. The OnSelectedNodeChange event is never get fired. Below is my code excerpt: In TreePane.aspx
8
12758
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the form. I only want to allow single selection, so using checkboxes is out of the question. It works as is, but it makes the form very cumbersome if every time that a user selects a node, the whole page has to reload. Is there a way to have a node...
2
5509
by: makennedy | last post by:
Hi Experts, Please help, I am a newbie to ASP.NET 2.0 may be I am doing something wrong or there may be a bug somewhere. Basically I have a TreeView Control which I have created programmatically. And I want to bind the selection of a TreeNode (which is a record) from the database) to a DetailsView which shows the datatable record for the selected TreeView node in the Details View. I am using IDE : Visual Web Developer 2005 Express; OS=...
0
1898
by: Falcula | last post by:
Hello, I have a treeview that i fill from a database, when i update nodename in database the treeview dont update. Its works when iam not useing enableviewstate="true" but then i loosing the current selection and stuff in the tree. I post my code here, any idea ?
1
2312
by: ton | last post by:
Hi, How can I limit the size of a treeview on a webform so the user can scroll on its page. I've allready placed the control in a DIV like: <div style="OVERFLOW:auto; WIDTH:100%; HEIGHT:140px"> <asp:TreeView style="Z-INDEX: 100; LEFT: 0px; POSITION: absolute; TOP: 0px" Height="200px" id="TreeView1" runat="server" ImageSet="XPFileExplorer"
1
4397
by: =?Utf-8?B?TG9yZW4=?= | last post by:
I’m having a couple of problems using the TreeView control on a windows form. I feel as if I’m missing something very obvious, but I not seeing it! Any suggestions would be appreciated. 1. I’d like to change the background color of the selected treeview node. To do this it looks as if I need to change the treeview’s SelectedNodeStyle property. MSDN states that “this property is read-only; however, you can set the properties...
0
8581
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8514
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9050
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8932
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8766
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8778
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6439
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.