Hi I have a treeview and listview. Which, based on a command line param will show the contents of a specific folder. However the problem I have is that when I click around in the treeview the list keeps being refreshed so that any subfolders keep on being duplicated in the treeview so a folder with only one subfolder ends up looking like it has several. Hope that makes sense.
Below is the code for the treeview.

VB Code:
  1. Private Sub Load1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3.         Try
  4.             Dim cla As String() = Environment.GetCommandLineArgs()
  5.  
  6.             If cla.Length = 1 Then
  7.                 Me.lblPatientid1.Text = "No command line arguments passed."
  8.             Else
  9.                 Me.lblPatientid1.Text = cla(1)
  10.             End If
  11.  
  12.             If Directory.Exists("C:\" & cla(1)) Then
  13.                 tvwDirectories.Nodes.Add("C:\" & cla(1))
  14.                 'load the treeview with file contents
  15.                 RefreshTreeView("C:\" & cla(1), tvwDirectories.Nodes(0))
  16.             Else
  17.                 MessageBox.Show("No file found for this ID", "No File Found", MessageBoxButtons.OK)
  18.             End If
  19.         Catch ex As Exception
  20.             MessageBox.Show("An error has occured please try again", "Error", MessageBoxButtons.OK)
  21.         End Try
  22.     End Sub
  23.  
  24.  
  25.  
  26.     Private Sub tvwDirectories_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwDirectories.AfterSelect
  27.         Try
  28.             ' load the treeview with subdirectories of current selection
  29.             RefreshTreeView(e.Node.Text, e.Node)
  30.             'Load the list view with files of current selection
  31.             RefreshListView(e.Node.Text)
  32.         Catch ex As Exception
  33.             MessageBox.Show("An error has occured please try again", "Error", MessageBoxButtons.OK)
  34.         End Try
  35.     End Sub
  36.  
  37.  
  38.     Sub RefreshTreeView(ByVal strDir As String, ByVal tnRoot As TreeNode)
  39.         Try
  40.             'Get Directory Information
  41.             Dim StrDirArray() As String = Directory.GetDirectories(strDir)
  42.             If StrDirArray.Length <> 0 Then
  43.                 'Populate the treeview control with all subdirectories in the current directory
  44.                 Dim d As String
  45.                 Dim tnNode As TreeNode
  46.                 For Each d In StrDirArray
  47.                     tnNode = New TreeNode(d)
  48.                     tnRoot.Nodes.Add(tnNode)
  49.                 Next
  50.             End If
  51.         Catch ex As Exception
  52.             MessageBox.Show("An error has occured please try again", "Error", MessageBoxButtons.OK)
  53.         End Try
  54.     End Sub
  55.  
  56.  
  57.     Sub RefreshListView(ByVal strDir As String)
  58.         Try
  59.             lvwfiles.Items.Clear()
  60.             'Get File information
  61.             Dim Files() As FileInfo = New DirectoryInfo(strDir).GetFiles()
  62.             'Populate the listview with all files in the current directory
  63.             Dim f As FileInfo
  64.             Dim newfile As ListViewItem
  65.             For Each f In Files
  66.                 newfile = lvwfiles.Items.Add(f.FullName)
  67.                 newfile.ImageIndex = 0
  68.             Next
  69.         Catch ex As Exception
  70.             MessageBox.Show("An error has occured please try again", "Error", MessageBoxButtons.OK)
  71.         End Try
  72.  
  73.     End Sub
  74.  
  75.     Private Sub lvwfiles_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvwfiles.DoubleClick
  76.  
  77.         'If File.Exists(lvwfiles.SelectedItems(0).Text) = True Then MessageBox.Show("Yes it exists")
  78.         '  If Not DirectCast(Me.Owner, Form1).PicImage.Image Is Nothing Then
  79.         Dim File As FileInfo = New FileInfo(lvwfiles.SelectedItems(0).Text)
  80.         DirectCast(Me.Owner, Form1).PicImage.Image = Image.FromFile(lvwfiles.SelectedItems(0).Text)
  81.         DirectCast(Me.Owner, Form1).lblScanDate1.Text = String.Format("File Date:     {0}", File.LastWriteTime.ToLongDateString())
  82.         DirectCast(Me.Owner, Form1).lblfilename1.Text = String.Format("File Name:     {0}", File.Name.ToString)
  83.         DirectCast(Me.Owner, Form1).lblimageno1.Show()
  84.         'picimage.Image = Image.FromFile(lvwfiles.SelectedItems(0).Text)
  85.         'MessageBox.Show(String.Format(lvwfiles.SelectedItems(0).Text))
  86.         Me.Close()
  87.     End Sub

I am pretty sure it's in the "Refreshtreeview"sub but i cannot figure it out.

Thanks in advance