关于ListView::ColumnWidthChanging没响应问题的研究

ColumnWidthChanging 算是一个bug吧

起初我就纳闷,为什么同一个项目在笔记本上运行的好好的,跑到台式机上就无效了呢?原本是想利用这个事件来控制列表视控件,以固定某些列的宽度,在网上找资料,纷纷提出只要使得ColumnWidthChangingEventArgs e 中的e.Cancel = true;就可以了,查看msdn的说明,确实也是这么个意思,试了一下,竟然不行!愤怒之余,又上网找资料,说,还得添加e.NewWidth = listview1.Columns[e.ColumnIndex].Width;再试,终于可以了(笔记本),于是心花怒放的移植到了台式机中的项目中,竟然发现不行,实在是火都大。于是把笔记本上的实验项目拿过来测,确实不行,仔细调试一看,笔记本上ColumnWidthChanging的事件被触发了,而台式机上的ColumnWidthChanging事件根本没有响应过,火大啊,又遇到无厘头的问题了。再上网找资料,大部分都是关于要不要调用e.NewWidth = listview1.Columns[e.ColumnIndex].Width的争执。遇到跟我发现一样的比较少,而也基本没有找到原因所在。我是个比较固执的人,虽然可以用其他办法解决,但是不找到原因心里总是放不下,于是继续百度谷歌百度谷歌。。。。,偶尔在他人博客中看到这么一段说明:

In order to receive the ListView::ColumnWidthChanging, you need to enable full dragging of windows.

Here is how to enable full dragging of windows:
1. Go to Control Panel
2. Click on Display
3. On the "Display Properties" dialog go to "Appereance" tab
4. On the "Appearance" tab click on "Effects" button - this will open the "Effects" dialog.
5. On the "Effects" dialog see if the "Show windows contents while dragging" check box is checked. If the check box is not checked, then check it.
6. Close the "Effects" dialog and then the "Display Properties" dialog.

Now full dragging of windows should be enabled on your machine and the ListView should fire the ColumnWidthChanging event.
好吧,我承认第一次我没看懂,可能也因为我不太信博主,因为那哥们的博文,有些是中文,有些是全英文,我料他想必是直接COPY过来的,恐怕没验证过就直接发布,所以粗略看了一下,Control Panel 控件面板?窗体面板?去到项目的窗体面包,控件上,死活找不到有关于display的选项,在控件属性里也没看到相关的选项。于是没管它了,再搞了大半天也没找到解决方案。搁置了一会,过了一天,心中依然烦闷,于是再搜,在一个英文论坛中又看到了上面的说明,是来自VS2005 Product Team.想必是微软的技术团队,于是重视起来,仔细想一下Control Panel -》?  Control Panel -》?  Control Panel -》?   Control Panel -》控制面板,windows系统控制面板?进入控制面板,display-》显示选项?点击进去,找到了外观tab页面(Appereance)。。。明白了,在外观页面找到了效果按钮(Effects),并把“拖动时显示窗口内容”打上勾,

再运行项目,ColumnWidthChanging果然触发了,我哩个去,坑爹呢这是!后面写到We are investigating this issue. (我们正在探究这个问题),我哩个去!估计也算是bug了,最后在msdn上好像有说e.NewWidth = lv_detailsContainer.Columns[e.ColumnIndex].Width;是必须的。最后有:

 private void listview1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
        {
            //允许样品名称固定列宽
            if (e.ColumnIndex != 2)
            {
                e.NewWidth = lv_detailsContainer.Columns[e.ColumnIndex].Width;
                e.Cancel = true;
            }
          }

但是,如果在每个电脑上安装时都让用户设置这个选项,似乎不太合理,看来这个偷懒的方案必须放弃了,所以还是按众位所说,先记录列的宽度,然后在ColumnWidthChanged事件发生后修改回来好了,或者自己去处理mousemove事件。

仅次与大家分享,若有意见,欢迎指点!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值