title: Why is this gap showing up in my ListView?
body: <p>I have a C# WinForm application where I am using a ListView to show what files have been uploaded to my database. I use the same code each time, calling <code>LoadFileAttachments()</code> when the form loads, and again any time I refresh the list, or add or remove additional attachments from the database. (This part works great)</p>
  
  <p>Where I am having an issue is the GUI side of the ListView. The first time <code>LoadFileAttachments()</code> runs and fills the ListView, there is a gap between the left side of the ListView and the attachments. On subsequent calls, the gap disappears.</p>
  
  <p>As you can see below, the columns are not changing width, there just seems to be a gap. I tried capturing the MouseClick event of the ListView and using a ListViewHitTestInfo to see what was there, and it is showing the item I am clicking next to, with the property of "Selected = false". Clicking on the icon or text causes the item to be selected, but not in the gap.</p>
  
  <p><strong>What's causing the gap?</strong></p>
  
  <p>Screenshot:</p>
  
  <p><a href="http://img831.imageshack.us/img831/4054/fileattachments.png" rel="nofollow noreferrer" title="What&#39;s causing the gap?">Screenshot of the gap/no gap http://img831.imageshack.us/img831/4054/fileattachments.png</a></p>
  
  <p>The code I call each time:</p>
  
  <pre><code>private void LoadFileAttachments()
  {
      attachmentListView.Items.Clear();
      ImageList iconList = new ImageList();
      attachmentListView.LargeImageList = iconList;
      attachmentListView.SmallImageList = iconList;
      attachmentListView.StateImageList = iconList;
  
      FileAttachmentInfo[] fileAttach = dbAccess.RetrieveAttachedRecords(loadPNGid.Value);
      foreach (FileAttachmentInfo file in fileAttach)
      {
          ListViewItem item = new ListViewItem(file.FileName);
          item.Tag = file.RowID;
          iconList.Images.Add(file.FileExtention, ExtractIcons.GetIconImage(file.FileExtention));
          item.ImageKey = file.FileExtention;
          item.SubItems.Add(GetFileTypeDescriptors.GetFileDescriptor(file.FileExtention));
          item.SubItems.Add(Conversions.FileSizeToString(file.FileSize));
          item.SubItems.Add(file.DateAdded.ToShortDateString());
          attachmentListView.Items.Add(item);
      }
  
      if (attachmentListView.Columns.Count == 0)
      {
          attachmentListView.Columns.Add("Attachment", 150);
          attachmentListView.Columns.Add("File type", -2);
          attachmentListView.Columns.Add("Size", -2);
          attachmentListView.Columns.Add("Date added", -2);
      }
  }
  </code></pre>
  
  <p>This is the code in the designer file:</p>
  
  <pre><code>// 
  // attachmentListView
  // 
  this.attachmentListView.AllowColumnReorder = true;
  this.attachmentListView.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  this.attachmentListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
  this.attachmentListView.Location = new System.Drawing.Point(0, 0);
  this.attachmentListView.MultiSelect = false;
  this.attachmentListView.Name = "attachmentListView";
  this.attachmentListView.Size = new System.Drawing.Size(440, 301);
  this.attachmentListView.TabIndex = 0;
  this.attachmentListView.TileSize = new System.Drawing.Size(188, 130);
  this.attachmentListView.UseCompatibleStateImageBehavior = false;
  this.attachmentListView.View = System.Windows.Forms.View.Details;
  this.attachmentListView.DoubleClick += new System.EventHandler(this.attachmentListView_DoubleClick);
  this.attachmentListView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.attachmentListView_MouseClick);
  </code></pre>