Ale*_*lex 14 c# listview winforms
我的项目是.NET/WinForms.
我有一个列表视图,总是填充项目.我希望它总是有选择.但是,如果单击列表视图项下方的空白区域,则会丢失选择.
该列表有多个selection = true和hide selection = false.
Han*_*ant 26
您需要阻止本机控件看到鼠标单击,以便它不会取消选择项目.在项目中添加一个新类并粘贴下面显示的代码.编译.将它从工具箱顶部放到表单上,替换现有表单.
using System;
using System.Drawing;
using System.Windows.Forms;
class MyListView : ListView {
protected override void WndProc(ref Message m) {
// Swallow mouse messages that are not in the client area
if (m.Msg >= 0x201 && m.Msg <= 0x209) {
Point pos = new Point(m.LParam.ToInt32());
var hit = this.HitTest(pos);
switch (hit.Location) {
case ListViewHitTestLocations.AboveClientArea :
case ListViewHitTestLocations.BelowClientArea :
case ListViewHitTestLocations.LeftOfClientArea :
case ListViewHitTestLocations.RightOfClientArea :
case ListViewHitTestLocations.None :
return;
}
}
base.WndProc(ref m);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5628 次 |
最近记录: |