nerd24
Messages postés41Date d'inscriptionlundi 10 mars 2008StatutMembreDernière intervention28 mars 2008
-
19 mars 2008 à 11:54
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 2021
-
19 mars 2008 à 16:34
Bonjour,
est ce que qqun saurait ou je peux trouver un cours en ligne sur vb.net dans lequel une partie est consacrée au treeview. J'ai beau chercher je trouve pas.
Merci d'avance
Public Class Form1
Private Structure SHFILEINFO
Public hIcon As IntPtr ' : icon
Public iIcon As Integer ' : icondex
Public dwAttributes As Integer ' : SFGAO_ flags
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public szDisplayName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
Public szTypeName As String
End Structure
Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
(ByVal pszPath As String, _
ByVal dwFileAttributes As Integer, _
ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, _
ByVal uFlags As Integer) As IntPtr
Private Sub AddImages(ByVal strFileName As String)
Dim shInfo As SHFILEINFO
shInfo = New SHFILEINFO()
shInfo.szDisplayName = New String(vbNullChar, MAX_PATH)
shInfo.szTypeName = New String(vbNullChar, 80)
Dim hIcon As IntPtr
hIcon = SHGetFileInfo(strFileName, 0, shInfo, Marshal.SizeOf(shInfo), SHGFI_ICON Or SHGFI_SMALLICON)
Dim MyIcon As Drawing.Bitmap
MyIcon = Drawing.Icon.FromHandle(shInfo.hIcon).ToBitmap
ImageList1.Images.Add(strFileName.ToString(), MyIcon)
End Sub
Private Sub AddAllFolders(ByVal TNode As TreeNode, ByVal FolderPath As String)
Try
For Each FolderNode As String In Directory.GetDirectories(FolderPath)
Dim SubFolderNode As TreeNode = TNode.Nodes.Add(FolderNode.Substring(FolderNode.LastIndexOf(""c) + 1))
SubFolderNode.Tag = FolderNode
SubFolderNode.Nodes.Add("Loading...")
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Tnode As TreeNode = TreeView1.Nodes.Add("(Drive C:)")
AddImages("C:\Windows")
AddAllFolders(Tnode, "C:")
ListView1.View = View.Details
' Add a column with width 80 and left alignment
ListView1.Columns.Add("File Name", 150, HorizontalAlignment.Left)
ListView1.Columns.Add("File Type", 80, HorizontalAlignment.Left)
ListView1.Columns.Add("Date Modified", 150, HorizontalAlignment.Left)
End Sub
Private Sub Treeview1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Dim FileExtension As String
Dim SubItemIndex As Integer
Dim DateMod As String
ListView1.Items.Clear()
If TreeView1.SelectedNode.Nodes.Count 1 AndAlso TreeView1.SelectedNode.Nodes(0).Text "Loading..." Then
End If
Dim folder As String = CStr(e.Node.Tag)
If Not folder Is Nothing AndAlso IO.Directory.Exists(folder) Then
Try
For Each file As String In IO.Directory.GetFiles(folder)
e.Node.Nodes.Add(file.Substring(file.LastIndexOf(""c) + 1))
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
If Not folder Is Nothing AndAlso IO.Directory.Exists(folder) Then
Try
For Each file As String In IO.Directory.GetFiles(folder)
FileExtension = IO.Path.GetExtension(file)
DateMod = IO.File.GetLastWriteTime(file).ToString()
AddImages(file)
ListView1.Items.Add(file.Substring(file.LastIndexOf(""c) + 1), file.ToString())
ListView1.Items(SubItemIndex).SubItems.Add(FileExtension.ToString() & " File")
ListView1.Items(SubItemIndex).SubItems.Add(DateMod.ToString())
SubItemIndex += 1
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Private Sub Treeview1_BeforeExpand(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand
If e.Node.Nodes.Count 1 AndAlso e.Node.Nodes(0).Text "Loading..." Then
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 19 mars 2008 à 16:18
euh... en modifiant la propriété ImageList de ton TreeView
et SmallImageList de ton ListView
ces propriétés sont accessibles via le panneau des taches de ces controles (la petite fleche en haut a droite de ces controles quand tu les selectionne)
nerd24
Messages postés41Date d'inscriptionlundi 10 mars 2008StatutMembreDernière intervention28 mars 2008 19 mars 2008 à 15:17
En fait je suis debutant et meme avec les livres et ce que je vais voir sur internet j'ai beaucoup de mal.
Mais il existe pas un petit code que je mettrai dans Form1.vb pour le realiser. Je pensais que c'etait un truc qui se faisait couramment.
nerd24
Messages postés41Date d'inscriptionlundi 10 mars 2008StatutMembreDernière intervention28 mars 2008 19 mars 2008 à 15:56
Merci je pense que c'est exactement ce que je cherche.
Un dernier truc. J'ai lu vite fait le document e tout a la fin il y a ecrit :
Add the Call to the AddImages function, in the TreeView_AfterSelect event, just underneath DateMod = IO.File.GetLastWriteTime(file).ToString()
Est ce que tu pourrais me preciser ce que je dois faire, ce que je dois ecrire plus precisement et ou?