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 displays files and folders.
ViewStyle := Report; CheckBoxes := True;
The WindowProc is a special procedure every TControl uses to respond to messages sent to the control.
Here's how to get notified when an item in the list view is checked or un-checked:
- Drop a TListView (name "ListView1") on a Delphi form. Add some items to the list view.
- Set ViewStyle to vsReport,
- Set CheckBoxes to true,
- In the form's OnCreate event hijack the ListView1's WindowProc.
- If the message being processed in CN_Notify (Delphi extension to the WM_NOTIFY message) and if the notification message is "LVN_ITEMCHANGED",
- Read the tagNMLISTVIEW record to grab additional data.
- If this is a state change (LVIF_STATE) and if the state of an item changes (LVIS_STATEIMAGEMASK) grab the changed item, read it's Checked property.
uses CommCtrl; procedure TForm1.FormCreate(Sender: TObject) ;
begin
OriginalListViewWindowProc := ListView1.WindowProc;
ListView1.WindowProc := ListViewWindowProcEx;
end; procedure TForm1.ListViewWindowProcEx(var Message: TMessage) ;
var listItem : TListItem;
begin if Message.Msg = CN_NOTIFY then
begin
if PNMHdr(Message.LParam)^.Code = LVN_ITEMCHANGED then
begin
with PNMListView(Message.LParam)^ do
begin
if (uChanged and LVIF_STATE) <> then
begin
if ((uNewState and LVIS_STATEIMAGEMASK) shr ) <> ((uOldState and LVIS_STATEIMAGEMASK) shr ) then
begin
listItem := listView1.Items[iItem];
memo1.Lines.Add(Format('%s checked:%s', [listItem.Caption, BoolToStr(listItem.Checked, True)])) ;
end;
end;
end;
end;
end; //original ListView message handling OriginalListViewWindowProc(Message) ;
end;
procedure TForm1.GetCheckedButtonClick(Sender: TObject) ;
var li : TListItem;
begin
memo1.Lines.Clear; memo1.Lines.Add('Checked Items:') ;
for li in listView1.Items do
begin
if li.Checked then
begin
memo1.Lines.Add(Format('%s %s %s', [li.Caption, li.SubItems[], li.SubItems[]])) ;
end;
end;
end;
Note: Reading the description of the tagNMLISTVIEW record in the Windows API help, reveals that "uChanged" field notifies that the item attributes have changed. This field is zero for notifications that do not use it. Otherwise, it can have the same values as the mask member of the LVITEM record. Bits 12 through 15 of the "state" member specify the state image index. To isolate these bits, use the LVIS_STATEIMAGEMASK.
Implementing the On Item Checked Event for the TListView Control的更多相关文章
- 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 ther ...
- remove all event handlers from a control
The sample code below will remove all Click events from button1 public partial class Form1 : Form { ...
- Atitit vod click event design flow 视频点播系统点击事件文档
Atitit vod click event design flow 视频点播系统点击事件文档 重构规划1 Click cate1 Click mov4 重构规划 事件注册,与事件分发管理器分开 ...
- Ext JS treegrid 发生的在tree上增加itemclick 与在其它列上增加actioncolumn 发生事件冲突(event conflict)的解决办法
Ext JS treegrid 发生的在tree上增加itemclick 与在其它列上增加actioncolumn 发生事件冲突(event conflict)的解决办法 最近在适用Ext JS4开发 ...
- React(0.13) 定义一个checked组件
<!DOCTYPE html> <html> <head> <title>React JS</title> <script src=& ...
- 使用 Item,ItemManager 在 XNA 中创建物品和道具(十六)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- vue.js动态绑定input的checked
不管<input type='radio checked='true''> 你的checked属性值是true或者false,他都会选中. 其实原理是这样的,复选框里只要有checked ...
- embody the data item with the ability to control access to itself
Computer Science An Overview _J. Glenn Brookshear _11th Edition Such communication needs have long b ...
- about the pageload and page init event
Page_Init The Page_Init event is the first to occur when an ASP.NET page is executed. This is where ...
随机推荐
- C# 文本框只能输入数字和退格键 (转)
C# 文本框只能输入数字和退格键 private void TextBox_KeyPress(object sender, KeyPressEventArgs e) { if(e.Key ...
- mySQL 教程 第4章 数据查询
mySQL运算符 这些运算符在SQL查询中用得到. 算数运算符 + 加 - 减 * 乘 / DIV 除 % MOD 取余数 比较运算符 = 等于 <> != 不等于 < <= ...
- 一组十六进制的字符串每两个转成对应值的byte
/// <summary> /// 一组十六进制的字符串每两个转成对应值的byte,比如4142 会成 AB对应的byte列表 /// </summary> /// <p ...
- opencv中的图像形态学——腐蚀膨胀
腐蚀膨胀是图像形态学比较常见的处理,腐蚀一般可以用来消除噪点,分割出独立的图像元素等. 一般腐蚀操作对二值图进行处理,腐蚀操作如下图,中心位置的像素点是否与周围领域的像素点颜色一样(即是否是白色点,即 ...
- SpringCloud初体验:五、Sidecar 将 PHP 这类非 Java 生态语言的服务接入 Spring Cloud
先起一个 Sidecar 服务,一个PHP服务一个应用,和PHP服务部署在同一台机子,通过 localhost 访问,这样就解决了网络开销,相当于本地进程间调用 Sidecar 服务比较简单, 1.这 ...
- git 不能拉取时,检查是不是被杀毒软件给干掉了
我这儿是 \Git\bin\sh.exe 被干掉了. 添加排除,并从隔离区中还原.
- eclipse中的XML文件无法快捷键注释问题
好多朋友都发现在ME6.0或跟高版本中“Ctrl+Shift+c”或者是“Ctrl+Shift+/”快捷键无论你怎么点,它就是不起作用,恼火吧? 百度 还是 google 都没有找到 合理的说法,更有 ...
- 管道和FIFO 一
管道和FIFO 管道(pipe) 管道在Unix及Linux进程间通信是最基础的,很容易理解.管道就像一个自来水管,一端注入水,一端放出水,水只能在一个方向上流动,而不能双向流动.管道 ...
- 安卓手机安装虚拟定位的方法Xposed安装器+模拟位置(Xposed模块)
原文:https://www.52pojie.cn/thread-571328-1-1.html 未测试,据说只支持某些手机,小米和华为很难安装,建议买其他品牌. Xposed安装器步骤:·ROOT你 ...
- 【转载】html中object标签详解
[转载自http://blog.csdn.net/soliy/archive/2010/03/22/5404183.aspx] html标签之Object标签详解 作者:网络 出处:网络 ...