使用vb.net的TreeView [英] TreeView using vb.net

查看:106
本文介绍了使用vb.net的TreeView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

常规TreeView结构,其级别在左侧指示.

0 01603301
1 43​​57848M91
2 4277562M91
3 4277563M1
3 1441447X1
3 4277564M91
1 43​​57848M91
2 4277562M91
3 4277563M1
3 1441447X1
3 4277564M91
4 1441447X1
1 43​​57848M91
1 43​​55777M91
2 1441447X1
2 1441447X1
1 1441447X1
1 1441447X1

我需要以下级别,而不是常规的Treeview级别.

0 01603301
1 43​​57848M91
2 4277562M91
3 4277563M1
3 1441447X1
3 4277564M91
1 43​​57848M91
4 4277562M91
5 4277563M1
5 1441447X1
5 4277564M91
6 1441447X1
1 43​​57848M91
1 43​​55777M91
7 1441447X1
7 1441447X1
1 1441447X1
1 1441447X1

离开0和1级别后,其他级别必须按上述方法处理.
如何实现呢?
任何建议和帮助都会有所帮助.
在此先感谢.

Hi all,

The General TreeView Structure, with the level indicated in the left.

0 01603301
1 4357848M91
2 4277562M91
3 4277563M1
3 1441447X1
3 4277564M91
1 4357848M91
2 4277562M91
3 4277563M1
3 1441447X1
3 4277564M91
4 1441447X1
1 4357848M91
1 4355777M91
2 1441447X1
2 1441447X1
1 1441447X1
1 1441447X1

I need the level as follows instead of the general Treeview Level.

0 01603301
1 4357848M91
2 4277562M91
3 4277563M1
3 1441447X1
3 4277564M91
1 4357848M91
4 4277562M91
5 4277563M1
5 1441447X1
5 4277564M91
6 1441447X1
1 4357848M91
1 4355777M91
7 1441447X1
7 1441447X1
1 1441447X1
1 1441447X1

Leaving the 0 and 1 levels, the other levels has to be treated as above.
How to achieve this?
Any suggetion and help will be helpful.
Thanks in advance.

推荐答案

如果只有一个地方,您可以搜索
If only there was a place you could search for articles[^] on TreeViews...


这是我必须执行treeview列表的代码.
This is the 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
                tree_nodes(level).EnsureVisible()
            End If
        Next i
        If trv.Nodes.Count > 0 Then trv.Nodes(0).EnsureVisible()
    End Sub
End Class



离开0和1级别后,其他级别必须增加.
任何建议都会有所帮助.
预先感谢.



Leaving the 0 and 1 levels, the other levels has to be incremented.
Any suggestions will be helpful.
Thanks in advance.


这篇关于使用vb.net的TreeView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆