Hi All,
I currently have a button which upon clicking allows me to add the details & icon of the selected file from the OpenFileDialog window. This all works fine but when selecting a second file, the icon from the first ListView item changes to the newly selected file but the other information remains unchanged. Below is the code I am using. Any suggestions as to what I am doing wrong?
vb Code:
Dim openDLG As New OpenFileDialog Dim listItem As New ListViewItem Dim ImageList As New ImageList openDLG.Title = "Select the file that you would like to upload." openDLG.Filter = "All File Sources (*.*)|*.*" If openDLG.ShowDialog = Windows.Forms.DialogResult.OK Then Try Dim DirectoryName As String = New System.IO.FileInfo(openDLG.FileName).DirectoryName Me.lvwAttachments.BeginUpdate() Me.lvwAttachments.SmallImageList = ImageList ImageList.Images.Add(0, Drawing.Icon.ExtractAssociatedIcon(openDLG.FileName).ToBitmap) listItem.ImageIndex = 0 listItem.SubItems.Add(New System.IO.FileInfo(openDLG.FileName).Name) If DirectoryName.EndsWith("\") Then listItem.SubItems.Add(New System.IO.FileInfo(openDLG.FileName).DirectoryName) Else listItem.SubItems.Add(New System.IO.FileInfo(openDLG.FileName).DirectoryName & "\") End If Me.lvwAttachments.Items.Add(listItem) 'AutoResize ListView Columns Me.lvwAttachments.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent) 'Resize columns to the larger of content or header AdjustColumnToFill(Me.lvwAttachments) 'Adjust Last Column To Fill ListView AdjustLastColumnToFill(Me.lvwAttachments) Me.lvwAttachments.EndUpdate() Catch ex As Exception MessageBox.Show(ex.Message) End Try End If




Reply With Quote