Microsoft.Web.UI.Webcontrol Treeview

G

Guest

I would like to convert the code below into an asp.net application where I
can run it via the web. It works ok for vb.net, but my goal is to do it
through the browser. I have in a few areas, in particular the
"application.startuppath" where it's not part of the System.Web.
HttpApplicationState. Another area is "trv.Nodes.Add(text_line.Trim())"
where value of type string cannot be converted to
Microsoft.web.ui.webcontrol.treenode. Also, the "EnsureVisible" not
supported it seems. I didn't include the file organization.txt, but it could
be any file that has tabs denoting the tree structure.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim file_name As String = Application.StartupPath
file_name = file_name.Substring(0, file_name.Length - 1)
file_name = file_name.Substring(0, file_name.LastIndexOf("\"))
file_name &= "\organization3.txt"
LoadTreeViewFromFile(file_name, TreeView1)
End Sub

' Load a TreeView control from a file that uses tabs
' to show indentation.
Private Sub LoadTreeViewFromFile(ByVal file_name As String, ByVal trv As
TreeView)
' Get the file's contents.
Dim stream_reader As New StreamReader(file_name)
Dim file_contents As String = stream_reader.ReadToEnd()
stream_reader.Close()

' Remove line feeds.
file_contents = file_contents.Replace(vbLf, "")

' Break the file into lines.
Const charCR As Char = CChar(vbCr)
Const charTab As Char = CChar(vbTab)


Dim lines() As String = file_contents.Split(charCR)

' Process the lines.
Dim text_line As String
Dim level As Integer
Dim tree_nodes() As TreeNode
Dim num_nodes As Integer = 0
ReDim tree_nodes(num_nodes)
Dim cHA As Char
cHA = " "c
trv.Nodes.Clear()
For i As Integer = 0 To lines.GetUpperBound(0)
text_line = lines(i)
If text_line.Trim().Length > 0 Then
' See how many tabs are at the start of the line.
level = text_line.Length - text_line.TrimStart(charTab).Length

' Make room for the new node.
If level > num_nodes Then
num_nodes = level
ReDim Preserve tree_nodes(num_nodes)
End If

' Add the new node.
If level = 0 Then
tree_nodes(level) = trv.Nodes.Add(text_line.Trim())
Else
tree_nodes(level) = tree_nodes(level -
1).Nodes.Add(text_line.Trim())
End If
tree_nodes(level).EnsureVisible()
End If
Next i

If trv.Nodes.Count > 0 Then trv.Nodes(0).EnsureVisible()
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top