我发现,由于添加的内容会增加一些空格,列表视图现在错误地计算了“自动调整大小”列的宽度,因此当有人自动调整一些列的大小(例如双击列调整大小的控点)时,该列的大小被调整,使其太小,而该列表视图中的文字则在结尾处以括号(.)排列。
是否有办法可以让我在列表视图中问我在自动调整大小时栏的大小?
我发现,由于添加的内容会增加一些空格,列表视图现在错误地计算了“自动调整大小”列的宽度,因此当有人自动调整一些列的大小(例如双击列调整大小的控点)时,该列的大小被调整,使其太小,而该列表视图中的文字则在结尾处以括号(.)排列。
是否有办法可以让我在列表视图中问我在自动调整大小时栏的大小?
没有一条信息可以告诉您列将自动调整大小。 但正如您所提到的, 用户只能用两种方式触发 : 双击分隔符, 和 < code> Ctrl- Shift- / code> 。 您可以截取这两条, 然后做任何你想做的事 。
步骤 # 1: 要拦截双击鼠标, 您需要使用子类 < code> ListView code > 并监听 < code> HDN_ DIVIDERDDDLLICK code> 通知 :
protected override void WndProc(ref Message m) {
switch (m.Msg) {
case 0x4E: // WM_NOTIFY
if (!this.HandleNotify(ref m))
base.WndProc(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
protected bool HandleNotify(ref Message m) {
const int HDN_DIVIDERDBLCLICKW = (HDN_FIRST - 25);
NativeMethods.NMHEADER nmheader = (NativeMethods.NMHEADER)m.GetLParam(typeof(NativeMethods.NMHEADER));
switch (nmheader.nhdr.code) {
case HDN_DIVIDERDBLCLICKW:
if (nmheader.iItem >= 0 && nmheader.iItem < this.Columns.Count) {
this.AutoResizeColumn(nmheader.iItem);
m.Result = (IntPtr)1; // prevent the change from happening
return true;
}
break;
default:
break;
}
return false;
}
当然, 您必须执行 < code> AutoResize Column () code > 来做你想做的事 。
步骤 # 2 截取 Ctrl- Shift- + 时, 您需要推翻 < code> processKeyPreview code > 。 < a href=" http://www.codeproject. com/ artes/22570/ overriding- Keydown- a- User- control- untrol- user- Process" rel= "nown" 标题=" this art article" > 将显示您如何做到这一点。 您的覆盖中, 您会为每列调用 < code > AutResizecolumn () 。
如果您构造您的 ListViewemts
, 使每个子项的“ W” 字符串与所有者想要绘制的数据的长度相同, 则控制将使用这些字符串自动计算列。 这可能是一个简单的方法 。
您可以在以下两个场景中手动完成此操作 : enger@ / em >
如果您想要修正 minimimimwidth
和 最大Width
,
在 Column Width changing
事件 ListView
中使用此功能:
int minimumWidth = 200;
int maximumWidth = 500;
if (e.NewWidth maximumWidth)
{
e.Cancel = true;
e.NewWidth = maximumWidth;
}
If you want to fix a ColumnWidth
for the ListViewColumn
, Set
the desired ColumnWidth
在 Column Width changing
事件 ListView
中使用此功能:
ListView ColumnList = sender as ListView;
e.Cancel = true;
e.NewWidth = ColumnList.Columns[e.ColumnIndex].Width;
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...