15,747,059 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View Javascript questions
View C++ questions
View Python questions
View Java questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by vijay2482 (Top 3 by date)
vijay2482
31-Mar-11 3:43am
View
Code:
<Pre>
If level = 0 Then
tree_nodes(level) = trv.Nodes.Add(text_line.Trim() & level) ElseIf level = 1 Then
tree_nodes(level) = tree_nodes(level - 1).Nodes.Add(text_line.Trim & level)
Else
'need to increment the levelfor all the sublevel with level>1
End If
<Pre>
vijay2482
31-Mar-11 2:05am
View
Deleted
This is the below code I have to do the treeview listing.
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.TreeView1 = New System.Windows.Forms.TreeView
Me.SuspendLayout()
'
'TreeView1
'
Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Fill
Me.TreeView1.ImageIndex = -1
Me.TreeView1.Location = New System.Drawing.Point(0, 0)
Me.TreeView1.Name = "TreeView1"
Me.TreeView1.SelectedImageIndex = -1
Me.TreeView1.Size = New System.Drawing.Size(292, 273)
Me.TreeView1.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.TreeView1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
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 &= "\test.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)
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() & level)
Else
tree_nodes(level) = tree_nodes(level - 1).Nodes.Add(text_line.Trim() & level)
End If
vijay2482
30-Mar-11 11:25am
View
Deleted
I have searched the articals already.
But did not find one, that matches my requirement.
I found a code, that does the treeview listing of a txt file, but as I mentioned, I want the levels to be written differently.
Thanks for your reply.