473,322 Members | 1,522 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,322 software developers and data experts.

Microsoft.Web.UI.Webcontrol Treeview

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
--
Hutty
Nov 19 '05 #1
1 3984
Just following up to see if anyone has any ideas on the solution below.

thanks

"Hutty" wrote:
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
--
Hutty

Nov 19 '05 #2

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

Similar topics

0
by: Jim M | last post by:
Is there any way to know what node was clicked in a treeview webcontrol where autopostback is false? Thanks in advance.
0
by: clintonG | last post by:
I'm just wondering how rich the TreeView control actually is having never worked with a tree view control. I want to load XML into the tree and I'd like control of the presentation tier by getting...
1
by: John | last post by:
Hi all, I've posted this before but received no answers and it is an issue . . . One of my pages is using a treeview webcontrol. I load the treeview with data which only has two levels (i.e....
1
by: Edward | last post by:
hello, everyone, I build one tree menu using TreeView webcontrol , everything is ok, from tree node click, one sub-frame(main) can refresh its content with new url. My question is, I have...
8
by: Charts | last post by:
I download IEWebControls.exe, and installed it. Installation created IE Web Controls directory. The readme.txt said, 3. Create a /bin subdirectory for the application and copy the file...
0
by: shen.chang.cs | last post by:
Hi, all, I use .Net V2.0 and WebControl TreeView. I want to have an OnClick() function to handle user click on certain end nodes but not on other nodes. Someone suggested to use a Java...
0
by: Henrik Stidsen | last post by:
I need to get the HTML output from a webcontrol as a string instead of it being rendered on the page. I have the following code: Dim SiteMapSource As New SiteMapDataSource() Dim TreeView1...
0
by: Bill | last post by:
Is it possible to have different contect menus for each node in a TreeView control. I see lots of examples on how to do this using Windows Forms, but the the webcontrol does not seem to support...
0
by: mike2006 | last post by:
Can anybody give the examples of code in C# for insert, remove, navigate, search of data, set of backcolor in WebControl TreeView in Visual Web Developer 2005?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.