A
AspirinAUS
Guest
Hello geniuses!
I am not experienced in the area of the ListView control.
I would like it to allow the user to view and navigate through their own folders and files through this listview. I have achieved this with the following code:
Imports System
Imports System.IO
Public Class frmList
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 txtFolder As System.Windows.Forms.TextBox
Friend WithEvents cmdList As System.Windows.Forms.Button
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents lvwFiles As System.Windows.Forms.ListView
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.txtFolder = New System.Windows.Forms.TextBox()
Me.cmdList = New System.Windows.Forms.Button()
Me.lvwFiles = New System.Windows.Forms.ListView()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
txtFolder
Me.txtFolder.Location = New System.Drawing.Point(8, 8)
Me.txtFolder.Name = "txtFolder"
Me.txtFolder.Size = New System.Drawing.Size(454, 20)
Me.txtFolder.TabIndex = 1
Me.txtFolder.Text = "c:\"
cmdList
Me.cmdList.Location = New System.Drawing.Point(468, 8)
Me.cmdList.Name = "cmdList"
Me.cmdList.Size = New System.Drawing.Size(72, 24)
Me.cmdList.TabIndex = 2
Me.cmdList.Text = "List Files"
lvwFiles
Me.lvwFiles.Location = New System.Drawing.Point(8, 166)
Me.lvwFiles.Name = "lvwFiles"
Me.lvwFiles.Size = New System.Drawing.Size(532, 90)
Me.lvwFiles.TabIndex = 3
Me.lvwFiles.UseCompatibleStateImageBehavior = False
Me.lvwFiles.View = System.Windows.Forms.View.Tile
PictureBox1
Me.PictureBox1.Location = New System.Drawing.Point(8, 34)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(532, 126)
Me.PictureBox1.TabIndex = 4
Me.PictureBox1.TabStop = False
frmList
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(552, 266)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.lvwFiles)
Me.Controls.Add(Me.cmdList)
Me.Controls.Add(Me.txtFolder)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frmList"
Me.Text = " File List Example - (c) 2002 - tHe_cLeanER"
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
Private Sub cmdList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdList.Click
********************
THIS SECTION IS NOT REQUIRED TO LIST FILES, IT JUST PREPARES THE LISTVIEW.
lvwFiles.View = View.Details SET REPORT STYLE
lvwFiles.Items.Clear() CLEAR ALL FROM PREVIOUS TIME
lvwFiles.Columns.Clear()
lvwFiles.Columns.Add("Filename", 300, HorizontalAlignment.Left) CREATE COLOUMS AT RUN TIME
lvwFiles.Columns.Add("Extension", 45, HorizontalAlignment.Center)
lvwFiles.Columns.Add("Size (KB)", 50, HorizontalAlignment.Center)
lvwFiles.Columns.Add("Create Time", 120, HorizontalAlignment.Center)
*********************
Dim dFolder As DirectoryInfo = New DirectoryInfo(txtFolder.Text)
Dim fFileArray() As FileInfo = dFolder.GetFiles
FILEARRAY NOW HOLDS ALL THE FILES IN THE SELECTED FOLDER
Dim fFile As FileInfo
Dim lCurrent As ListViewItem
LOOP THROUGH ARRAY, LISTING ALL FILES IN LISTVIEW
For Each fFile In fFileArray
lCurrent = lvwFiles.Items.Add(fFile.Name)
lCurrent.SubItems.Add(fFile.Extension)
lCurrent.SubItems.Add(fFile.Length \ 1024 + 1) CONVERT BYTES TO KB
lCurrent.SubItems.Add(fFile.CreationTime)
Next
End Sub
End Class
The problem is, I would like to make the files selectable, so that a user can open them. Also, a search function where as you type in the name of the file, the ListView hides/clears the irrelevant items, so only the relevant items populate the ListView. I was wondering if it was possible to find the icons from each of the files being viewed by the ListView, copy them to an ImageList, to be transferred to the correct files?
Thanks for your help guys! P.S. I have Visual Basic 2010 Express on Windows 7
This is my designer, and Ive labeled the controls as to what they are in the code:
Continue reading...
I am not experienced in the area of the ListView control.
I would like it to allow the user to view and navigate through their own folders and files through this listview. I have achieved this with the following code:
Imports System
Imports System.IO
Public Class frmList
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 txtFolder As System.Windows.Forms.TextBox
Friend WithEvents cmdList As System.Windows.Forms.Button
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents lvwFiles As System.Windows.Forms.ListView
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.txtFolder = New System.Windows.Forms.TextBox()
Me.cmdList = New System.Windows.Forms.Button()
Me.lvwFiles = New System.Windows.Forms.ListView()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
txtFolder
Me.txtFolder.Location = New System.Drawing.Point(8, 8)
Me.txtFolder.Name = "txtFolder"
Me.txtFolder.Size = New System.Drawing.Size(454, 20)
Me.txtFolder.TabIndex = 1
Me.txtFolder.Text = "c:\"
cmdList
Me.cmdList.Location = New System.Drawing.Point(468, 8)
Me.cmdList.Name = "cmdList"
Me.cmdList.Size = New System.Drawing.Size(72, 24)
Me.cmdList.TabIndex = 2
Me.cmdList.Text = "List Files"
lvwFiles
Me.lvwFiles.Location = New System.Drawing.Point(8, 166)
Me.lvwFiles.Name = "lvwFiles"
Me.lvwFiles.Size = New System.Drawing.Size(532, 90)
Me.lvwFiles.TabIndex = 3
Me.lvwFiles.UseCompatibleStateImageBehavior = False
Me.lvwFiles.View = System.Windows.Forms.View.Tile
PictureBox1
Me.PictureBox1.Location = New System.Drawing.Point(8, 34)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(532, 126)
Me.PictureBox1.TabIndex = 4
Me.PictureBox1.TabStop = False
frmList
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(552, 266)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.lvwFiles)
Me.Controls.Add(Me.cmdList)
Me.Controls.Add(Me.txtFolder)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frmList"
Me.Text = " File List Example - (c) 2002 - tHe_cLeanER"
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
Private Sub cmdList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdList.Click
********************
THIS SECTION IS NOT REQUIRED TO LIST FILES, IT JUST PREPARES THE LISTVIEW.
lvwFiles.View = View.Details SET REPORT STYLE
lvwFiles.Items.Clear() CLEAR ALL FROM PREVIOUS TIME
lvwFiles.Columns.Clear()
lvwFiles.Columns.Add("Filename", 300, HorizontalAlignment.Left) CREATE COLOUMS AT RUN TIME
lvwFiles.Columns.Add("Extension", 45, HorizontalAlignment.Center)
lvwFiles.Columns.Add("Size (KB)", 50, HorizontalAlignment.Center)
lvwFiles.Columns.Add("Create Time", 120, HorizontalAlignment.Center)
*********************
Dim dFolder As DirectoryInfo = New DirectoryInfo(txtFolder.Text)
Dim fFileArray() As FileInfo = dFolder.GetFiles
FILEARRAY NOW HOLDS ALL THE FILES IN THE SELECTED FOLDER
Dim fFile As FileInfo
Dim lCurrent As ListViewItem
LOOP THROUGH ARRAY, LISTING ALL FILES IN LISTVIEW
For Each fFile In fFileArray
lCurrent = lvwFiles.Items.Add(fFile.Name)
lCurrent.SubItems.Add(fFile.Extension)
lCurrent.SubItems.Add(fFile.Length \ 1024 + 1) CONVERT BYTES TO KB
lCurrent.SubItems.Add(fFile.CreationTime)
Next
End Sub
End Class
The problem is, I would like to make the files selectable, so that a user can open them. Also, a search function where as you type in the name of the file, the ListView hides/clears the irrelevant items, so only the relevant items populate the ListView. I was wondering if it was possible to find the icons from each of the files being viewed by the ListView, copy them to an ImageList, to be transferred to the correct files?
Thanks for your help guys! P.S. I have Visual Basic 2010 Express on Windows 7
This is my designer, and Ive labeled the controls as to what they are in the code:

Continue reading...