Hi, trying to use Microsoft Treeview control w/dynamically populated nodes. The problem is that the first node in the tree is always selected (by default - and you can reset to some other node, but it would not allow to have NO NODES SELECTED) and as a result
when user clicks on it, OnSelectionChange event can not fire. It only works if you click on some other node and then again on the noad that was selected on load, so that selected index actually changes. So if a user has permissions to see only one node then
he can not do anything with it. I would like the tree to display with no nodes selected - so that all of the nodes that are shown as link work. Do you have any ideas on how to make it show with no noads selected on page load? Tried: on page load - TreeControl.SelectedNodeIndex
= null or ""; - first node still gets selected. Also tried TreeControl.Autoselect=false;
Hi, i have the same problem. If you know how to solve it please post it or send me the solution nunos7@hotmail[dot]com. Change [dot] . Thanks, Nuno Santos
Oh,-- My tree has expand/collapse functionality, but each node is displayed as a link. It represents categories and subcategories. When a user clicks on category or subcategory - onSelectionChanged event fires performing the search for documents falling into
selected category. When a user expands a category, they see subcategories undeneath. Here is my tree: In the code from dataset I set id of the node to be CategoryID and node Text to be Category Name, so the output is like this: General Information Operations
Merchandising and I simply perform the search based on the ID of the node that the user clicks on. So the problem is that by default Tree Control has first node in the tree (Node with the index of 0) selected like so: Fixtures As a result, when the user clicks
on it nothing happens (cuz slected status does not change) - so what I am trying to do is to overwrite this default so that the first node of the tree is not selected and all of my links are clickable.
:)....Sorry my BAD english!....:) Hi, I fix the problem with a url in every node. My tree is diferent, i make the tree from a sql server data base , xml and xslt on the xslt page i have the Category Name, Category ID, and URL AND TARGET, when the users
clicks in one node open de url... How to overwrite the default node selected?
Hi everybody, I work with VS Net. Ich try to understand how treeview works. I have a treview in my sample page and want to get click functions. For example i want to open a aspx page (test.aspx) or make a pannel visible or invisible by click on any child node.
I treied to give for a child target propery as test.aspx. But on click on child no pape oppened, and no panel visibility happened. Can anyboy give a siple examlpe how it works? thaks Halisce
Say you wanna call this event: onselectedindexchange You add this routine:
Sub ShowPanel(sender As Object, e As TreeViewSelectEventArgs)
'Makes each Panel Visible or Invisible, depdending on which node is clicked.
Select Case MyTree.selectedNodeIndex
'red
Case "0.0"
panel1.visible="true"
panel2.visible="False"
panel3.visible="False"
panel4.visible="False"
'blue
Case "0.1"
panel1.visible="False"
panel2.visible="true"
panel3.visible="False"
panel4.visible="False"
'yellow
Case "1.0"
panel1.visible="False"
panel2.visible="False"
panel3.visible="true"
panel4.visible="False"
'green
Case "1.1"
panel1.visible="False"
panel2.visible="False"
panel3.visible="False"
panel4.visible="True"
End Select
End Sub
MyTree is my treeview id of course. And I inserted 4 panels in my page (id="Panel1"...). Each panel has its own BackColor (red, bue, yellow and green). selectedNodeIndex refers
to the index level (e.g. "0.0"). But I still have a probl. I'd like to disable visibility for several panels at once. If someone has a pointer...
Here is an example I can think of off hand, sorry written in c#, not sure about casting objects in VB... The FindControl method has come in extremely handy for me. private void Button1_Click(object sender, System.EventArgs e) { MakeOneVisible("Panel2"); } ///
/// use to have a list of multiple objects, and request only one be visible /// /// private void MakeOneVisible(string ObjectId) { //First make them all not visible Panel1.Visible=false; Panel2.Visible=false; Panel3.Visible=false; Panel4.Visible=false; //FindControl
will find any object by ID Control cPanel = FindControl(ObjectId); //should probably be error handling here in case control is not found... //Control must be cast as type of control in order to access the correct members ((Panel)cPanel).Visible=true; }
For an extremely silly work around you might consider making a top.top level node that has no function other than to be highlighted at first. i.e. Your Tools ->GeneralInfo ---->Operations ---->Merchandising
Sub ShowPanel(sender As Object, e As TreeViewSelectEventArgs)
'Makes all panels invisible
'still need to set visible="False" to all the objects' IDs containing string "panel"
Panel1.visible="False"
panel2.visible="False"
panel3.visible="False"
panel4.visible="False"
Select Case MyTree.selectedNodeIndex
'red
Case "0.0"
Panel1.visible="true"
'blue
Case "0.1"
panel2.visible="true"
'yellow
Case "1.0"
panel3.visible="true"
'green
Case "1.1"
panel4.visible="True"
End Select
End Sub
But I'm still looking for sumthin shorter. Avoiding a select case. Setting visible="True" only for the clicked node index. An awful stuff like: MyTree.selectedNodeIndex = e.NewNode.ToString() Panel(e.NewNode.ToString()).visible="true"
OK, this might be a bit much, but here is a class that I use for that type of thing, also just for getting the text that is selected. The idea is to fake a "Command" in each of the tree nodes by using HTML comments. Tree node text would be: "node2"; Thus on
display the command is hidden. use selectedindexchange event to get it. here is the code for a tree called tvTestView: private void tvTestView_SelectedIndexChange(object sender, Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e) { // to hold the command
value TreeNodeData tnd = new TreeNodeData(tvTestView.Nodes, e.NewNode); Response.Write(tnd.NodeText + "
"); Response.Write(tnd.CommandText + "
"); //look for a command value } don't know if there is a better way to do this, but here is the class that will return both the text of a given node, and the command if you used it: using System; using System.Collections; using Microsoft.Web.UI.WebControls;
namespace My.Web.Util { /// /// used to find the text for any node in a tree. /// public class TreeNodeData { private string sNodeText=""; private string sCommandText = ""; /// /// Returns the node text that was found during object instantiation (command is
removed if there was one) /// public string NodeText { get { if (sCommandText.Length != 0) return sNodeText.Substring(sCommandText.Length + 7); else return sNodeText; } } /// /// Command Text. If you have used a command, this will return that string /// public
string CommandText { get { return sCommandText; } } /// /// Pass in TreeView.Nodes, and the index of the node. /// public TreeNodeData(TreeNodeCollection TreeViewDotNodes, string Index) { //find the text and the command, if aplicable, from the node in the
tree. string[] SplitIndex = Index.Split('.'); int Depth = 0; //if the index is further down in the tree, start a recursive loop //to find the actual node if (SplitIndex.Length - 1 > Depth) { sNodeText = this.FindSubNodeTextByIndex(TreeViewDotNodes[int.Parse(SplitIndex[Depth])].Nodes,
SplitIndex, Depth+1); } else { sNodeText = TreeViewDotNodes[int.Parse(SplitIndex[Depth])].Text; } int iCommandIndex = sNodeText.IndexOf("")-4; this.sCommandText = sNodeText.Substring(iCommandIndex+4,iCommandLength); } } private string FindSubNodeTextByIndex
(TreeNodeCollection tnc, string[] Index, int StartDepth) { string NodeText = ""; if (Index.Length - 1 > StartDepth) { NodeText = FindSubNodeTextByIndex(tnc[int.Parse(Index[StartDepth])].Nodes, Index, StartDepth+1); } else { NodeText = tnc[int.Parse(Index[StartDepth])].Text;
} return NodeText; } } }
anoli
Member
10 Points
2 Posts
Treeview node selected
Oct 13, 2003 06:26 PM|LINK
NSANTOS
Member
20 Points
4 Posts
Re: Treeview node selected
Oct 15, 2003 09:44 AM|LINK
anoli
Member
10 Points
2 Posts
To clarify - Treeview node selected
Oct 15, 2003 05:54 PM|LINK
NSANTOS
Member
20 Points
4 Posts
Re: To clarify - Treeview node selected
Oct 16, 2003 08:29 AM|LINK
Halisce
Member
5 Points
1 Post
Re: To clarify - Treeview node selected
Oct 26, 2003 06:09 PM|LINK
Bill2clone
Star
9975 Points
1995 Posts
Re: Halisce
Oct 27, 2003 02:27 PM|LINK
Sub ShowPanel(sender As Object, e As TreeViewSelectEventArgs) 'Makes each Panel Visible or Invisible, depdending on which node is clicked. Select Case MyTree.selectedNodeIndex 'red Case "0.0" panel1.visible="true" panel2.visible="False" panel3.visible="False" panel4.visible="False" 'blue Case "0.1" panel1.visible="False" panel2.visible="true" panel3.visible="False" panel4.visible="False" 'yellow Case "1.0" panel1.visible="False" panel2.visible="False" panel3.visible="true" panel4.visible="False" 'green Case "1.1" panel1.visible="False" panel2.visible="False" panel3.visible="False" panel4.visible="True" End Select End SubMyTree is my treeview id of course. And I inserted 4 panels in my page (id="Panel1"...). Each panel has its own BackColor (red, bue, yellow and green). selectedNodeIndex refers to the index level (e.g. "0.0"). But I still have a probl. I'd like to disable visibility for several panels at once. If someone has a pointer...Tressleworks modules
DNN & webhosting
IEWCtrls
synthmusic
Member
15 Points
3 Posts
Re: Halisce
Oct 28, 2003 10:39 AM|LINK
synthmusic
Member
15 Points
3 Posts
Re: To clarify - Treeview node selected
Oct 28, 2003 10:51 AM|LINK
Bill2clone
Star
9975 Points
1995 Posts
Re: still searching
Oct 28, 2003 03:30 PM|LINK
Sub ShowPanel(sender As Object, e As TreeViewSelectEventArgs) 'Makes all panels invisible 'still need to set visible="False" to all the objects' IDs containing string "panel" Panel1.visible="False" panel2.visible="False" panel3.visible="False" panel4.visible="False" Select Case MyTree.selectedNodeIndex 'red Case "0.0" Panel1.visible="true" 'blue Case "0.1" panel2.visible="true" 'yellow Case "1.0" panel3.visible="true" 'green Case "1.1" panel4.visible="True" End Select End SubBut I'm still looking for sumthin shorter. Avoiding a select case. Setting visible="True" only for the clicked node index. An awful stuff like: MyTree.selectedNodeIndex = e.NewNode.ToString() Panel(e.NewNode.ToString()).visible="true"Tressleworks modules
DNN & webhosting
IEWCtrls
synthmusic
Member
15 Points
3 Posts
Re: still searching
Oct 28, 2003 11:53 PM|LINK
"); Response.Write(tnd.CommandText + "
"); //look for a command value } don't know if there is a better way to do this, but here is the class that will return both the text of a given node, and the command if you used it: using System; using System.Collections; using Microsoft.Web.UI.WebControls; namespace My.Web.Util { /// /// used to find the text for any node in a tree. /// public class TreeNodeData { private string sNodeText=""; private string sCommandText = ""; /// /// Returns the node text that was found during object instantiation (command is removed if there was one) /// public string NodeText { get { if (sCommandText.Length != 0) return sNodeText.Substring(sCommandText.Length + 7); else return sNodeText; } } /// /// Command Text. If you have used a command, this will return that string /// public string CommandText { get { return sCommandText; } } /// /// Pass in TreeView.Nodes, and the index of the node. /// public TreeNodeData(TreeNodeCollection TreeViewDotNodes, string Index) { //find the text and the command, if aplicable, from the node in the tree. string[] SplitIndex = Index.Split('.'); int Depth = 0; //if the index is further down in the tree, start a recursive loop //to find the actual node if (SplitIndex.Length - 1 > Depth) { sNodeText = this.FindSubNodeTextByIndex(TreeViewDotNodes[int.Parse(SplitIndex[Depth])].Nodes, SplitIndex, Depth+1); } else { sNodeText = TreeViewDotNodes[int.Parse(SplitIndex[Depth])].Text; } int iCommandIndex = sNodeText.IndexOf("")-4; this.sCommandText = sNodeText.Substring(iCommandIndex+4,iCommandLength); } } private string FindSubNodeTextByIndex (TreeNodeCollection tnc, string[] Index, int StartDepth) { string NodeText = ""; if (Index.Length - 1 > StartDepth) { NodeText = FindSubNodeTextByIndex(tnc[int.Parse(Index[StartDepth])].Nodes, Index, StartDepth+1); } else { NodeText = tnc[int.Parse(Index[StartDepth])].Text; } return NodeText; } } }