473,406 Members | 2,259 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,406 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 1375

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...
0
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...
0
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...

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.