title: Adding items to VB.NET ListView and having them shown in the order they were added
body: <p>I am creating an app launcher - that is basically a ListView with a "group" of shortcuts files ( ie images associated with a shortcut and the text is the name of the shortcut ) in it.  It's all been working fine and dandy, except this last thing that I want to do.  The apps that appear in the listview are stored in an xml file and what I'm trying to do is add the apps into the listview in the order they appear in the xml file i.e. this probably won't be alphabetical.</p>
  
  <p>So I read an app name from the xml file, find it's shortcut lnk file, extract the icon from the file and add it to the Listview; using:</p>
  
  <pre><code>lvPrograms.LargeImageList = ProgramIcons
  
  Dim item As ListViewItem
  
  Dim FileName = Path.GetFileNameWithoutExtension(shortcutFile.Name)
  
  item = New ListViewItem(FileName, 1)
  item.ImageKey = FileName
  iconFile = System.Drawing.Icon.ExtractAssociatedIcon(shortcutFile.FullName)
  
  ProgramIcons.Images.Add(FileName, iconFile)
  lvPrograms.Items.Add(item)
  </code></pre>
  
  <p>I also set the Sorting property of the listView to None</p>
  
  <p>When the code has added all the apps, I was hoping for them to appear in the order I added them, but it just seems to add them in a random order ie.. not my order or ascending or descending ?!</p>
  
  <p>If I check the contents of lvPrograms.Items(X).Text in the debug window, then (0) is not the first one I added and (6) is not the seventh one I added ?!</p>
  
  <p>Hope this makes sense and someone could help me get the apps listed in the order that I added them ?</p>
  
  <p>Cheers,</p>
  
  <p>Chris.</p>
  
  <p>Extra Info asked for my Plutonix:</p>
  
  <p>Basically my xml is read into an object called UserAppSettings which has a collection of Application objects and their Name property if the name of the app.  Also the ProgramDetails is a structure that holds various properties about a shortcut - name, working folder etc  </p>
  
  <p>The image lists (in case relevant are 32bit &amp; 16bit in depth )</p>
  
  <pre><code>    lvPrograms.Clear()
      ProgramIcons.Images.Clear()
      ProgramIconsSmall.Images.Clear()
  
      lvPrograms.LargeImageList = ProgramIcons
      lvPrograms.SmallImageList = ProgramIconsSmall
  
  
      Dim dir As New System.IO.DirectoryInfo(userShortcutsFolder)
  
      lvPrograms.BeginUpdate()
      lvPrograms.Sorting = SortOrder.None
  
      Dim shortcutFile As FileInfo
  
      For Each AppToShow As Application In UserAppSettings.Applications
          shortcutFile = New FileInfo(userShortcutsFolder + AppToShow.Name + ".lnk")
          addShortcutToListView(shortcutFile)
      Next
  
  
      Private Sub addShortcutToListView(shortcutFile As FileInfo)
  
      Dim CurrentProgram As ProgramDetails
      Dim item As ListViewItem
  
      CurrentProgram = New ProgramDetails
      With CurrentProgram
          .FullName = shortcutFile.FullName
          .Name = shortcutFile.Name
          .NameWithoutExtension = Path.GetFileNameWithoutExtension(shortcutFile.Name)
  
          item = New ListViewItem(.NameWithoutExtension, 1)
          .Icon = System.Drawing.Icon.ExtractAssociatedIcon(.FullName)
  
          getShortcutProperties(CurrentProgram)
  
          ProgramIcons.Images.Add(.NameWithoutExtension, .Icon)
          ProgramIconsSmall.Images.Add(.NameWithoutExtension, .Icon)
  
          item.ImageKey = .NameWithoutExtension
      End With
  
      item.Tag = CurrentProgram
  
      lvPrograms.Items.Add(item)
      '   MsgBox(item.Text + vbNewLine + lvPrograms.Items(lvPrograms.Items.Count - 1).Text)
  End Sub 
  </code></pre>