Implementing On Item Click / Double Click for TListView
ListView.On Item Click & ListView.On Item Double Click
To be able to locate the clicked (if there is one) item when the OnClick event for the list view is fired, you need to determine what elements of the list view lie under the point specified by the X and Y parameters - that is the location of the mouse at the moment of "click".
The TListiew's GetHitTestInfoAt function returns information about the specified point in the list view’s client area.
To make sure the item was clicked (or double clicked) you need to call the GetHitTestInfoAt and react only if the click event occurred on an actual item.
Here's an example implementation of the ListView1's OnDblClick event:
//handles ListView1's On Double Click
procedure TForm.ListView1DblClick(Sender: TObject) ;
var
hts : THitTests;
ht : THitTest;
sht : string;
ListViewCursosPos : TPoint;
selectedItem : TListItem;
begin
//position of the mouse cursor related to ListView
ListViewCursosPos := ListView1.ScreenToClient(Mouse.CursorPos) ; //double click where?
hts := ListView1.GetHitTestInfoAt(ListViewCursosPos.X, ListViewCursosPos.Y) ; //"debug" hit test
Caption := '';
for ht in hts do begin
sht := GetEnumName(TypeInfo(THitTest), Integer(ht)) ;
Caption := Format('%s %s | ',[Caption, sht]) ;
end;
//locate the double-clicked item
if hts <= [htOnIcon, htOnItem, htOnLabel, htOnStateIcon] then
begin
selectedItem := ListView1.Selected; //do something with the double clicked item!
Caption := Format('DblClcked : %s',[selectedItem.Caption]) ;
end;
end;
In the OnDblClick (or OnClick) event handler, read the GetHitTestInfoAt function by providing it with the location of the mouse "inside" the control. To get the loction of the mouse related to the list view, the ScreenToClient function is used to convert a point (mouse X and Y) in screen coordinates to local, or client area, coordinates.
The GetHitTestInfoAt return a value of THitTests type. The THitTests is a set of THitTest enumerated values.
The THitTest enumeration values, with their description, are:
htAbove - above the client area.
htBelow - below the client area.
htNowhere - inside the control, but not on an item.
htOnItem - on an item, its text, or its bitmap.
htOnButton - on a button.
htOnIcon - on an icon.
htOnIndent - on the indented area of an item.
htOnLabel - on a label.
htOnRight - on the right side of an item.
htOnStateIcon - on a state icon or bitmap associated with an item.
htToLeft - to the left of the client area.
htToRight - to the right of the client area.
If the result of the call to GetHitTestInfoAt is a subset (Delphi sets!) of [htOnIcon, htOnItem, htOnLabel, htOnStateIcon] you can be sure the user clicked on the item (or on its icon / state icon).
Finally, if the above is true, read the Selected property of the list view, it returns the first selected item (if multiple can be selected) in the list view. Do something with the clicked / double clicked / selected item ...
e sure to download the full source code to explore the code and learn by adopting it :)
Implementing On Item Click / Double Click for TListView的更多相关文章
- Text selection in div(contenteditable) when double click
背景: 在最近项目中,碰到一个问题:有一个可编辑的div需要双击时可编辑,blur或者回车时将编辑结果保存.你可能注意到双击时,文字会被选中,可编辑区域不会focus到光标位置.考虑到兼容性问题,写了 ...
- [Python學習筆記] 使用 selenium 抓取網頁並且雙擊滑鼠 (double click)
一開始使用的時候 看官方文件 以為使用 double_click()即可 但後來出現錯誤 AttributeError: 'WebElement' object has no attribute 'd ...
- gulp die('click').live('click' composer
gulp die('click').live('click' composer packagist.org https://getcomposer.org/ 下载后 php composer.pha ...
- Implementing the On Item Checked Event for the TListView Control
The TListView Delphi control displays a list of items in a fashion similar to how Windows Explorer d ...
- 前端防抖,double click 克星
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 陈年佳酿之 - Winform ListView 控件 double click 事件中获取选中的row与column
背景 最近收到了一个关于以前项目的维护请求,那时的楼主还是刚刚工作的小青年~~~ 项目之前使用的是.net/winform.今天重新打开代码,看着之前在FrameWork2.0下面的代码, 满满的回忆 ...
- win10家庭版,双击bat文件无法运行(double click bat file does not execute)
win10家庭版,双击bat文件无法运行,弹出文件打开方式选择框. 在网上搜索处理办法,试了以下方法1-5都没有成功,用方法6规避. 方法1:打开一个驱动器,点“工具-文件夹选项→文件类型→新建→扩展 ...
- trigger click 和 click 的区别??
trigger click 和 user click 有什么区别吗? 好像没有的.直到发现了这样一段代码. <button class="btn1">Button< ...
- (WPF) 基本题
What is WPF? WPF (Windows Presentation foundation) is a graphical subsystem for displaying user inte ...
随机推荐
- python 正则表达式的使用
本文以例子的形势,介绍如何在python中使用正则表达式. Example1 #!/usr/bin/python import re import sys pattern = re.compile(r ...
- Maven 生成项目站点
Maven 不仅仅时一个自动化构建工具和一个依赖管理工具,他还能够帮助聚合项目信息,促进团队间的交流,POM 可以包含各种项目信息,如项目描述.版本控制系统地址.缺陷跟踪系统地址.许可证信息.开发者信 ...
- BaseAction编写:免去一些重复的代码,比如继承ActionSupport和实现ModelDriven接口
1.BaseAction package com.learning.crm.base; import java.lang.reflect.ParameterizedType; import java. ...
- winform截屏
引自 http://www.cnblogs.com/aland-liu/archive/2011/07/20/Winform.html 已经注册博客好久,一直由于工作原因没有打理.今天在网上看了一个截 ...
- Redis高速内存缓冲平台可视化监控之RedisLive配置实战
一.引用 这两天在弄Reids高速缓存平台的图形化监控,由于对于Python并不是很熟悉,安装过程中遇到了不少问题,包括: 1.python必备安装包的安装问题 2.Redis Live界面显示问题 ...
- Bootstrap table的一些简单使用总结
在GitHub上Bootstrap-table的源码地址是:https://github.com/wenzhixin/bootstrap-table Bootstrap-table的文档地址:http ...
- [转][SVN]常用操作
1. Commit 提交当前代码到 SVN 服务器. 2. 引用第三方类库时,不要从安装位置引用,而是在解决方案下,添加一个 lib 的目录,把需要的程序集复制到这里,然后从 lib 目录引用. 3 ...
- TraceLog.cs 累积 C#
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Dia ...
- Mybatis -代码自动生成(generatorConfig.xml)
参考:http://blog.csdn.net/jinshiyill/article/details/51546676 官方网址: http://www.mybatis.org/generator/c ...
- Java 运算符-=,+=混合计算详解
+=与-=运算符混合计算解析: int x = 3; x += x -= x -= x += x -= x; 详解:算数运算按运算符优先级运算,从右至左计算. 1. x=x-x; 实际为 3 - 3 ...