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:

  1. Drop a TListView (name "ListView1") on a Delphi form. Add some items to the list view.
  2. Set ViewStyle to vsReport,
  3. Set CheckBoxes to true,
  4. In the form's OnCreate event hijack the ListView1's WindowProc.
  5. If the message being processed in CN_Notify (Delphi extension to the WM_NOTIFY message) and if the notification message is "LVN_ITEMCHANGED",
  6. Read the tagNMLISTVIEW record to grab additional data.
  7. 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的更多相关文章

  1. 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 ...

  2. remove all event handlers from a control

    The sample code below will remove all Click events from button1 public partial class Form1 : Form { ...

  3. Atitit vod click event design flow  视频点播系统点击事件文档

    Atitit vod click event design flow  视频点播系统点击事件文档 重构规划1 Click cate1 Click  mov4 重构规划 事件注册,与事件分发管理器分开 ...

  4. Ext JS treegrid 发生的在tree上增加itemclick 与在其它列上增加actioncolumn 发生事件冲突(event conflict)的解决办法

    Ext JS treegrid 发生的在tree上增加itemclick 与在其它列上增加actioncolumn 发生事件冲突(event conflict)的解决办法 最近在适用Ext JS4开发 ...

  5. React(0.13) 定义一个checked组件

    <!DOCTYPE html> <html> <head> <title>React JS</title> <script src=& ...

  6. 使用 Item,ItemManager 在 XNA 中创建物品和道具(十六)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  7. vue.js动态绑定input的checked

    不管<input type='radio checked='true''>  你的checked属性值是true或者false,他都会选中. 其实原理是这样的,复选框里只要有checked ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. POJ2279杨氏矩阵+钩子定理

    题目:http://poj.org/problem?id=2279 有dp做法,但会MLE. dp的思想很好,是通过 “按身高由小到大往进放” 把 “身高小于” 的条件转化成 “放进去的先后” ,于是 ...

  2. Microsoft Dynamics CRM2011 导入解决方案时,失败的原因小结

    将大的自定义文件导入到 Microsoft Dynamics CRM 时发生超时? 如图: 首先: a.首先需要确认两面的CRM 环境是一致,比如都是Roll up 11等. b.然后确认导出解决方案 ...

  3. Microsoft Dynamics CRM 2011 常用JS 按F12 改动窗体上数据的方法

    1.按F12打开控制台输入下面代码: contentIFrame.Xrm.Page.getAttribute("new_status").setValue(50);//设值cont ...

  4. PHP时间处理

    1.介绍UNIX时间戳 格林威治时间 2.在PHP类中获取日期和时间 time(); getdate()输出数组 3.日期和时间的格式化 date("H-m-d H:i:s",ti ...

  5. C/C++动态分配连续空间,下标越界导致的free():invalid next size问题

    昨天帮导师做的一个程序出了内存泄露的bug(在VS上程序运行一切正常,等return返回后才出错) 而且是程序运行结束后才出现的错误,在退出前一切代码都顺利执行完了,只是return之后出错. 之后我 ...

  6. ES之八:elasticsearch2.x下的JAVA API示例

    D:\soft\elasticsearch\elasticsearch-2.1.0\lib package com.dxz.es; import java.net.InetAddress; impor ...

  7. HUD 1175 连连看

    连连看 Time Limit : 20000/10000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submiss ...

  8. [转]winform CEF

    下载地址: http://opensource.spotify.com/cefbuilds/index.html 来自: NanUI 作者

  9. sping mvc+uploadify 上传文件大小控制3部曲

    页面使用uploadify 上传控件,使用spring CommonsMultipartipartResolver , 反向代理nginx nginx 配置文件 client_max_body_siz ...

  10. [UE4]Pawn和Controller,第一人称和第三人称切换

    一. Pawn 可以被控制的Actor,可以被Controller持有控制,并且从Controller中接受输入.例如:玩家.NPC(Not Player Character) 二.Controlle ...