473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Return selected node from IE treeview control

Hello All,

I wrote a function that will create a file system
directory for my web application and display it in the IE
Treeview control. Everything wrotes great! What I'm having
trouble with is return the full directory path for the
selected node (the file). Can someone review my procedure
for the tvMenu_SelectedIndexChange event? Here is my
source code:

****** Code Start Here *********

Dim strDirectories As String()
Dim strDirectory As String
Dim strFiles As String()
Dim strFile As String
Dim nodDirectory As TreeNode
Dim nodFile As TreeNode
Dim nodRoot As TreeNode
Dim strFullPath As String

Public Function LoadFiles(ByVal FolderName As String,
ByVal RootName As String)

Try
strDirectories = Directory.GetDirectories
(Server.MapPath(FolderName))
strfiles = Directory.GetFiles(Server.MapPath
(FolderName))

nodRoot = New TreeNode
nodRoot.Text = RootName
Me.tvMenu.Nodes.Add(nodRoot)

If strDirectories.Length <= 0 Then
For Each strFile In strFiles
nodFile = New TreeNode
nodFile.Text = strFile.Substring
(strFile.LastIndexOf("\") + 1)
nodRoot.Nodes.Add(nodFile)
Next
Else
For Each strDirectory In strDirectories
nodDirectory = New TreeNode
nodDirectory.Text =
strDirectory.Substring(strDirectory.LastIndexOf("\ ") + 1)
nodRoot.Nodes.Add(nodDirectory)
For Each strFile In Directory.GetFiles
(strDirectory)
nodFile = New TreeNode
nodFile.Text = strFile.Substring
(strFile.LastIndexOf("\") + 1)
nodDirectory.Nodes.Add(nodFile)
Next
Next
End If
Catch exLoadFiles As Exception
Throw exLoadFiles
End Try

Return LoadFiles

End Function

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
LoadFiles("PDF", "PDF Files")
LoadFiles("Excel", "MS Excel")
LoadFiles("Text", "Text Files")
LoadFiles("Word", "MS Word")
End If

End Sub

Private Sub tvMenu_SelectedIndexChange(ByVal sender As
Object, ByVal e As
Microsoft.Web.UI.WebControls.TreeViewSelectEventAr gs)
Handles tvMenu.SelectedIndexChange
Response.Write(Me.tvMenu.Nodes.Item
(Me.tvMenu.SelectedNodeIndex).Text)

End Sub

******* Code End Here *********
Jul 21 '05 #1
0 1374

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

Similar topics

0
by: hzgt9b | last post by:
Using visual studio .NET 2003, VB: I'm experiencing an issue with a TreeView object when it gets focus - the first root node in the tree always gets selected when the control gets focus - even if...
0
by: Mike | last post by:
Hello All, I wrote a function that will create a file system directory for my web application and display it in the IE Treeview control. Everything wrotes great! What I'm having trouble with is...
1
by: jesper_lofgren | last post by:
Hello, Iam using Treeview control in asp.net 2.0. But have a problem. I use NavigateUrl BUT then viewstate is lost when clicked on a link i the menu. And the selected node is lost. Then i...
0
by: Jiho Han | last post by:
In 2.0, what I am seeing is an issue where although the browser shows a node as selected, in the server side, the control returns null for Selected property. Basically, I have a code that builds...
2
by: rfm | last post by:
I have a TreeView with 1 expanded top node, it has several childnodes (call it row A), which have childs of their own. The top node is selected correctly and all childnodes from the row A nodes...
1
by: Falcula | last post by:
Hello, I have a treeview control, when i select a item i navigate to url. But selected node is lost, it reset itself, loosing state. I post my code here. Thanks in advance. <script...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
1
by: =?Utf-8?B?Rmx5Z3V5?= | last post by:
I have a TreeView with so many nodes that it requires scroll bars. When the user selects a node the screen is refreshed and the selected node is no longer visible. The TreeView is opened to the...
9
by: auntiejack56 | last post by:
Hi, I've got a treeview, and I want to display the node text property that I have a) clicked on or b) highlighted using the up or down arrows
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.