vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Mails senden, abrufen und decodieren - ganz easy ;-)  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
Re: Treeview Nodes 
Autor: Maywood
Datum: 03.04.05 13:10

Zu welcher Fehlermeldung kommt es denn? Befinden sich in den Ordner auch nur Bilder (also bmp, gif, jpg usw.)?

Hier nocheinmal ein kmpl. Bsp., welches bei mir einwandfrei funktioniert:
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Collections
 
Namespace Tree1
    Public Class MainForm
        Inherits System.Windows.Forms.Form
 
        Public Sub New()
            MyBase.New()
            InitializeComponent()
        End Sub
 
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub
 
        Private components As System.ComponentModel.IContainer
 
        Private Sub InitializeComponent()
            Me.Button1 = New System.Windows.Forms.Button
            Me.Label1 = New System.Windows.Forms.Label
            Me.TreeView1 = New System.Windows.Forms.TreeView
            Me.SuspendLayout()
            '
            'Button1
            '
            Me.Button1.Location = New System.Drawing.Point(312, 352)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(150, 34)
            Me.Button1.TabIndex = 0
            Me.Button1.Text = "Button1"
            '
            'Label1
            '
            Me.Label1.AutoSize = True
            Me.Label1.Location = New System.Drawing.Point(13, 352)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(38, 14)
            Me.Label1.TabIndex = 1
            Me.Label1.Text = "Label1"
            '
            'TreeView1
            '
            Me.TreeView1.Location = New System.Drawing.Point(13, 13)
            Me.TreeView1.Name = "TreeView1"
            Me.TreeView1.Size = New System.Drawing.Size(449, 332)
            Me.TreeView1.TabIndex = 2
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(467, 393)
            Me.Controls.Add(Me.TreeView1)
            Me.Controls.Add(Me.Label1)
            Me.Controls.Add(Me.Button1)
            Me.Name = "Form1"
            Me.Text = "Form1"
            Me.ResumeLayout(False)
            Me.PerformLayout()
        End Sub
 
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
 
        Public Shared Sub Main()
            Dim fMainForm As New MainForm
            fMainForm.ShowDialog()
        End Sub
 
        Dim imgList As ImageList
        Dim idx As Integer
        '// Dim imgRoot As String = "E:\PCS"
        Dim imgRoot As String = "D:\Images"
 
        Private Sub Button1Click(ByVal sender As System.Object, ByVal e As _
          System.EventArgs) Handles Button1.Click
            Dim root As New MyTreeNode("My Images", _
            MyTreeNode.NodeType.IsRootNode, 0)
            Me.imgList.Images.Clear()
            idx = 0
            imgList.Images.Add(New Bitmap(4, 4))
            Me.TreeView1.ImageList = imgList
            Me.TreeView1.BeginUpdate()
            Me.TreeView1.Nodes.Add(root)
            Me.SearchImages(imgRoot, root.Nodes)
            Me.TreeView1.EndUpdate()
        End Sub
 
        Private Sub FillImageListAndNode(ByVal fileName As String, _
        ByRef NodeColl As TreeNodeCollection)
 
            Dim img As Image = Image.FromFile(fileName)
            imgList.Images.Add(img)
            idx += 1
            NodeColl.Add(New MyTreeNode(fileName, MyTreeNode.NodeType.IsImage, _
              idx))
        End Sub
 
        Private Sub GetImages(ByVal Dir As String, _
        ByRef NodeColl As TreeNodeCollection)
 
            For Each f As String In IO.Directory.GetFiles(Dir)
                FillImageListAndNode(f, NodeColl)
            Next
        End Sub
 
        Private Sub SearchImages(ByVal Dir As String, _
        ByRef NodeColl As TreeNodeCollection)
 
            Dim tn As New MyTreeNode(Dir, MyTreeNode.NodeType.IsFolder, 0)
            GetImages(Dir, tn.Nodes)
            NodeColl.Add(tn)
            For Each d As String In IO.Directory.GetDirectories(Dir)
                SearchImages(d, tn.Nodes)
            Next
        End Sub
 
        Private Sub MainFormLoad(ByVal sender As System.Object, ByVal e As _
          System.EventArgs) Handles MyBase.Load
 
            imgList = New ImageList
        End Sub
 
        Private Sub TreeView1AfterSelect(ByVal sender As System.Object, ByVal e _
          As System.Windows.Forms.TreeViewEventArgs)
 
            Dim tn As MyTreeNode = CType(Me.TreeView1.SelectedNode, MyTreeNode)
            Me.Label1.Text = "INFO: " + tn.ToString()
        End Sub
    End Class
 
    Public Class MyTreeNode
        Inherits TreeNode
        Public TreeNodeType As NodeType
 
        Public Sub New(ByVal Text As String, _
        ByVal NodeType As NodeType, _
        ByVal ImageIndex As Integer)
 
            Me.Text = Text
            Me.TreeNodeType = NodeType
            Me.ImageIndex = ImageIndex
            Me.SelectedImageIndex = Me.ImageIndex
        End Sub
 
        Public Enum NodeType
            IsFolder
            IsImage
            IsRootNode
        End Enum
 
        Public Overrides Function ToString() As String
            Return String.Format( _
            "Text: {0} " + _
            "ImageIndex: {1} " + _
            "NodeType: {2} ", _
            Me.Text, _
            Me.ImageIndex, _
            Me.TreeNodeType.ToString() _
            )
        End Function
    End Class
End Namespace
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Treeview Nodes2.178Eckhard28.03.05 17:20
Re: Treeview Nodes1.758Eckhard28.03.05 17:48
Re: Treeview Nodes1.671Maywood28.03.05 18:49
Re: Treeview Nodes1.673Eckhard28.03.05 19:46
Re: Treeview Nodes1.634Maywood28.03.05 20:14
Re: Treeview Nodes1.567Eckhard28.03.05 21:54
Re: Treeview Nodes1.570Maywood29.03.05 19:22
Re: Treeview Nodes1.570Eckhard29.03.05 19:48
Re: Treeview Nodes1.791Maywood29.03.05 20:01
Re: Treeview Nodes1.594Eckhard29.03.05 20:11
Re: Treeview Nodes1.535Maywood29.03.05 20:35
Re: Treeview Nodes1.564Eckhard29.03.05 20:43
Re: Treeview Nodes1.676Maywood30.03.05 21:16
Re: Treeview Nodes1.949Eckhard31.03.05 16:31
Re: Treeview Nodes1.595Maywood31.03.05 18:26
Re: Treeview Nodes1.638Eckhard01.04.05 18:50
Re: Treeview Nodes1.611Eckhard01.04.05 19:40
Re: Treeview Nodes1.602Maywood02.04.05 15:05
Re: Treeview Nodes1.612Eckhard02.04.05 15:36
Re: Treeview Nodes1.678Eckhard02.04.05 22:14
Re: Treeview Nodes1.697Maywood03.04.05 13:10
Re: Treeview Nodes1.560Eckhard03.04.05 18:01
Re: Treeview Nodes1.624Maywood03.04.05 18:28
Re: Treeview Nodes1.877Eckhard03.04.05 18:53
Re: Treeview Nodes - PS1.714Maywood03.04.05 18:57
Re: Treeview Nodes - PS1.616Eckhard03.04.05 19:10
Re: Treeview Nodes - PS1.601Maywood03.04.05 19:33
Re: Treeview Nodes - PS1.576Eckhard03.04.05 19:50
Re: Treeview Nodes1.753Eckhard08.04.05 19:15

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel