在TListview中使用鼠标进行多重选择? [英] Multiselect using mouse in TListview?

查看:54
本文介绍了在TListview中使用鼠标进行多重选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说您有一个带有TListView且启用了MultiSelect的表单.通常,您必须按Shift或Control键才能选择多个项目.如果我想让列表视图仅通过单击鼠标来选择/取消选择其他项目,该怎么做?

就像您单击item1然后单击item3一样,然后再次单击item1,则只会保留item3.

我没有在对象检查器中看到任何看起来相关的内置属性.我是否需要修改ListviewOnMouseDown或ListviewOnSelectItem才能更改选择?

解决方案

列表视图控件中未实现这种选择,可能是因为它们支持可独立检查的复选框,我不知道...

您必须自己修改行为.但是使用 OnMouseDown OnSelectItem 事件并不是真正合适的方法,因为在触发它们时已经进行了选择.下面的示例拦截了鼠标左键按下消息.

 类型TListView =类(vcl.comctrls.TListView)受保护的过程WMLButtonDown(var消息:TWMLButtonDown);消息WM_LBUTTONDOWN;结尾;过程TListView.WMLButtonDown(var消息:TWMLButtonDown);开始Message.Keys:= MK_CONTROL;遗传;结尾; 

您可以通过任何其他方式拦截消息,将其分配给 WindowProc ,派生新控件...当然,您也可以有条件地实现行为更改,或者希望测试并保留其他内容虚拟按键/按钮.在这种情况下,请参见文档./p>

Say you have a form with a TListView, with MultiSelect enabled. Normally you have to press shift or control to select multiple items. If I'd like to have the listview select/de-select additional items with only a mouse-click, how do I do that?

Like if you click item1 and then item3 both would be selected, and then if you click item1 again, it would leave only item3 selected.

I don't see any built in properties in the Object Inspector that look relevant. Do I need to modify my ListviewOnMouseDown or ListviewOnSelectItem to change the selection?

解决方案

This kind of selection is not implemented in listview controls, maybe because they support checkboxes which can be independently checked, I don't know...

You have to modify the behavior yourself. But using OnMouseDown or OnSelectItem events are not really appropriate, as the selection have already been carried out by the time they are fired. Below example intercepts left mouse button down message.

type
  TListView = class(vcl.comctrls.TListView)
  protected
    procedure WMLButtonDown(var Message: TWMLButtonDown);
      message WM_LBUTTONDOWN;
  end;

procedure TListView.WMLButtonDown(var Message: TWMLButtonDown);
begin
  Message.Keys := MK_CONTROL;
  inherited;
end;

You can intercept the message by any other means, assigning to WindowProc, deriving a new control... Of course you can also implement the behavioral change conditionally, or would like to test and preserve other virtual keys/buttons. See documentation in that case.

这篇关于在TListview中使用鼠标进行多重选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆