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:
  1. Dim openDLG As New OpenFileDialog
  2.         Dim listItem As New ListViewItem
  3.         Dim ImageList As New ImageList
  4.  
  5.         openDLG.Title = "Select the file that you would like to upload."
  6.         openDLG.Filter = "All File Sources (*.*)|*.*"
  7.  
  8.         If openDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
  9.  
  10.             Try
  11.  
  12.                 Dim DirectoryName As String = New System.IO.FileInfo(openDLG.FileName).DirectoryName
  13.  
  14.                 Me.lvwAttachments.BeginUpdate()
  15.                 Me.lvwAttachments.SmallImageList = ImageList
  16.  
  17.                 ImageList.Images.Add(0, Drawing.Icon.ExtractAssociatedIcon(openDLG.FileName).ToBitmap)
  18.  
  19.                 listItem.ImageIndex = 0
  20.  
  21.                 listItem.SubItems.Add(New System.IO.FileInfo(openDLG.FileName).Name)
  22.  
  23.                 If DirectoryName.EndsWith("\") Then
  24.                     listItem.SubItems.Add(New System.IO.FileInfo(openDLG.FileName).DirectoryName)
  25.                 Else
  26.                     listItem.SubItems.Add(New System.IO.FileInfo(openDLG.FileName).DirectoryName & "\")
  27.                 End If
  28.  
  29.                 Me.lvwAttachments.Items.Add(listItem)
  30.  
  31.                 'AutoResize ListView Columns
  32.                 Me.lvwAttachments.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
  33.                 'Resize columns to the larger of content or header
  34.                 AdjustColumnToFill(Me.lvwAttachments)
  35.                 'Adjust Last Column To Fill ListView
  36.                 AdjustLastColumnToFill(Me.lvwAttachments)
  37.  
  38.                 Me.lvwAttachments.EndUpdate()
  39.  
  40.             Catch ex As Exception
  41.                 MessageBox.Show(ex.Message)
  42.             End Try
  43.  
  44.         End If