如何添加到自定义列表视图用户控制编辑项目列组等任务?
Posted
技术标签:
【中文标题】如何添加到自定义列表视图用户控制编辑项目列组等任务?【英文标题】:How can I add to the custom listview user control the tasks like editing the items columns groups? 【发布时间】:2020-09-17 09:06:12 【问题描述】:这个控件的原因是让listview在滚动时停止闪烁。 闪烁已停止并且工作正常,但 listview 控件没有与常规 winforms listview 相同的属性。
在此屏幕截图中,带有 ListView Tasks 窗口的列表视图是常规列表视图,而空的较小矩形是自定义控件。
这是自定义控件列表视图代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace FileSearcher
public partial class ListViewCostumControl : UserControl
public static ListViewControl lvnf;
public ListViewCostumControl()
InitializeComponent();
lvnf = new ListViewControl();
lvnf.Location = new Point(50, 50);
lvnf.Size = new Size(50, 50);
lvnf.View = View.Details;
lvnf.Dock = DockStyle.Fill;
lvnf.SuspendLayout();
lvnf.LabelEdit = true;
lvnf.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
lvnf.Columns.Add("", 984, HorizontalAlignment.Left);
lvnf.Sorting = SortOrder.None;
this.Controls.Add(lvnf);
lvnf.ResumeLayout(false);
public class ListViewControl : System.Windows.Forms.ListView
public ListViewControl()
//Activate double buffering
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
//Enable the OnNotifyMessage event so we get a chance to filter out
// Windows messages before they get to the form's WndProc
this.SetStyle(ControlStyles.EnableNotifyMessage, true);
protected override void OnNotifyMessage(System.Windows.Forms.Message m)
//Filter out the WM_ERASEBKGND message
if (m.Msg != 0x14)
base.OnNotifyMessage(m);
private void ListViewNFTest_Load(object sender, EventArgs e)
【问题讨论】:
【参考方案1】:我自己添加了列,并获得了与原始列表视图控件相同的视图。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace FileSearcher
public partial class ListViewCostumControl : UserControl
public static ListView lvnf;
public ListViewCostumControl()
InitializeComponent();
lvnf = new ListView();
lvnf.Location = new Point(50, 50);
lvnf.Size = new Size(50, 50);
lvnf.View = View.Details;
lvnf.Dock = DockStyle.Fill;
lvnf.HideSelection = false;
lvnf.MultiSelect = false;
//lvnf.SuspendLayout();
//lvnf.LabelEdit = true;
//lvnf.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
lvnf.Columns.Add("Path", 212, HorizontalAlignment.Left);
lvnf.Columns.Add("Path", 90, HorizontalAlignment.Right);
lvnf.Columns.Add("Last modified", 120, HorizontalAlignment.Left);
lvnf.Columns.Add("", 984, HorizontalAlignment.Left);
lvnf.Sorting = SortOrder.None;
this.Controls.Add(lvnf);
lvnf.ResumeLayout(false);
public class ListView : System.Windows.Forms.ListView
public ListView()
//Activate double buffering
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
//Enable the OnNotifyMessage event so we get a chance to filter out
// Windows messages before they get to the form's WndProc
this.SetStyle(ControlStyles.EnableNotifyMessage, true);
protected override void OnNotifyMessage(System.Windows.Forms.Message m)
//Filter out the WM_ERASEBKGND message
if (m.Msg != 0x14)
base.OnNotifyMessage(m);
private void ListViewNFTest_Load(object sender, EventArgs e)
工作良好,没有任何闪烁。
【讨论】:
以上是关于如何添加到自定义列表视图用户控制编辑项目列组等任务?的主要内容,如果未能解决你的问题,请参考以下文章
Android - 将搜索栏添加到自定义列表视图和简单适配器