Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 930571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:21:26+00:00 2026-05-15T20:21:26+00:00

I have a C# WinForm application where I am using a ListView to show

  • 0

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 LoadFileAttachments() 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)

Where I am having an issue is the GUI side of the ListView. The first time LoadFileAttachments() 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.

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.

What’s causing the gap?

Screenshot:

Screenshot of the gap/no gap http://img831.imageshack.us/img831/4054/fileattachments.png

The code I call each time:

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);
    }
}

This is the code in the designer file:

// 
// 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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:21:27+00:00Added an answer on May 15, 2026 at 8:21 pm

    I believe the problem is being caused by your setting of the StateImageList property. According to the ListView.StateImageList documentation the StateImageList is an additional image list that is displayed along side the SmallImageList.

    The StateImageList property allows you to specify an ImageList that contains images to use to represent an application-specific state of an item in a ListView control. State images are displayed to the left of an icon for the item. You can use state images, such as checked and unchecked check boxes, to indicate application-defined item states. State images are visible in all views of the ListView control.

    Try commenting it out and see if that fixes your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my winform application gathering data using databinding. Everything looks fine except that
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have a WinForms application (I'm using VB) that can be minimized to the
I have an winforms application that was built using MVC. The controller is subscribing
I have a winforms application in which I am using 2 Forms to display
I am using VS2008 to develop a WinForms 2.0 application. I have read about
I have a Winform application built with C# and .Net 2.0. I have a
I have a winform application that uses some referenced web services to get data.
I have a WinForm application built with VS 2008 (C#) and SQL Server Express
I have a WinForms application with a DataGridView control and a column of DataGridViewButtonCell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.