我有一个C#WinForm应用程序,我在其中使用ListView显示哪些文件已上载到我的数据库。我每次都用相同的代码
LoadFileAttachments()
加载文件附件()
运行并填充ListView时,ListView左侧和附件之间存在间隙。在随后的通话中,差距消失了。
正如您在下面看到的,列的宽度没有改变,只是看起来有一个间隙。我尝试捕获ListView的MouseClick事件,并使用ListViewHittesInfo查看其中的内容,它显示了我单击旁边的项目,属性为“Selected=false”。单击图标或文本会导致选中项目,但不会选中间隙中的项目。
截图:
Screenshot of the gap/no gap http://img831.imageshack.us/img831/4054/fileattachments.png
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);
}
}
这是设计器文件中的代码:
//
// 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);