为什么这个差距显示在我的ListView? [英] Why is this gap showing up in my ListView?

查看:138
本文介绍了为什么这个差距显示在我的ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里我使用一个ListView显示哪些文件已被上传到我的数据库一个​​C#WinForm应用程序。我用同样的$ C $每次C,调用 LoadFileAttachments()加载窗体时,再任我刷新列表,或添加或删除的其他附件数据库。 (这部分的伟大工程)

在哪里我有一个问题,就是在ListView的GUI的一面。第一次 LoadFileAttachments()运行,并填充ListView控件,还有就是ListView和附件的左侧之间的差距。在随后的调用,差距会消失。

正如你可以看到下面,列不改变宽度,那里只是似乎是一个空白。我试图捕捉的ListView的MouseClick事件,并使用ListViewHitTestInfo看什么在那里,它是显示我点击旁边的项目,与财产选定=假。点击图标或文本导致的项目被选择,但不能在间隙

是什么造成的差距?

截图:

在code我打电话,每次:

 私人无效LoadFileAttachments()
{
    attachmentListView.Items.Clear();
    ImageList中iconList =新的ImageList();
    attachmentListView.LargeImageList = iconList;
    attachmentListView.SmallImageList = iconList;
    attachmentListView.StateImageList = iconList;    FileAttachmentInfo [] = fileAttach dbAccess.RetrieveAttachedRecords(loadPNGid.Value);
    的foreach(在fileAttach FileAttachmentInfo文件)
    {
        ListViewItem的项目=新的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(项目);
    }    如果(attachmentListView.Columns.Count == 0)
    {
        attachmentListView.Columns.Add(附件,150);
        attachmentListView.Columns.Add(文件类型,-2);
        attachmentListView.Columns.Add(大小,-2);
        attachmentListView.Columns.Add(加入日期,-2);
    }
}

这是在设计文件中的code:

  //
// attachmentListView
//
this.attachmentListView.AllowColumnReorder =真;
this.attachmentListView.Font =新System.Drawing.Font(濑越UI,9F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((字节)(0)));
this.attachmentListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.attachmentListView.Location =新System.Drawing.Point(0,0);
this.attachmentListView.MultiSelect = FALSE;
this.attachmentListView.Name =attachmentListView;
this.attachmentListView.Size =新System.Drawing.Size(440,301);
this.attachmentListView.TabIndex = 0;
this.attachmentListView.TileSize =新System.Drawing.Size(188,130);
this.attachmentListView.UseCompatibleStateImageBehavior = FALSE;
this.attachmentListView.View = System.Windows.Forms.Vi​​ew.Details;
this.attachmentListView.DoubleClick + =新System.EventHandler(this.attachmentListView_DoubleClick);
this.attachmentListView.MouseClick + =新System.Windows.Forms.MouseEventHandler(this.attachmentListView_MouseClick);


解决方案

我相信这个问题是由你的 StateImageList 属性的设置引起的。按照的ListView .StateImageList 文档 StateImageList 是沿侧显示一个附加的图像列表中的 SmallImageList


  

StateImageList 属性允许你指定包含图像使用重新present项目的应用程序特定的状态ListView控件的ImageList。状态的图像显示到该项目的图标的左侧。您可以使用状态图像,如选中和未选中复选框,以指示应用程序定义项目状态。国家形象是在ListView控件的所有视图可见。


尝试评论出来,看看是否能解决您的问题。

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:

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

解决方案

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.

这篇关于为什么这个差距显示在我的ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆