Microsoft.Web.UI.Webcontrol Treeview

Discussion in 'ASP .Net' started by =?Utf-8?B?SHV0dHk=?=, Jan 5, 2005.

  1. 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
    =?Utf-8?B?SHV0dHk=?=, Jan 5, 2005
    #1
    1. Advertising

  2. 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
    =?Utf-8?B?SHV0dHk=?=, Jan 21, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,298
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    524
    SpamProof
    Oct 21, 2003
  3. Edward
    Replies:
    1
    Views:
    386
    Edward
    Jul 20, 2004
  4. =?Utf-8?B?ZGF2aWQ=?=

    Microsoft TreeView: Microsoft.Web.UI.WebControls.dll

    =?Utf-8?B?ZGF2aWQ=?=, Apr 11, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,575
    Patrick Olurotimi Ige
    Apr 11, 2005
  5. Replies:
    1
    Views:
    188
    º£Ò»
    Apr 9, 2004
Loading...

Share This Page