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. opencart后台操作--第一节 多语言篇---中文语言包

    参考:http://www.cnblogs.com/404bozhu/p/5015108.html#3584448 OpenCart简体中文语言包 OpenCart V2.3.0.x 版权所有:www ...

  2. 【Spring学习笔记-MVC-9】SpringMVC数据格式化之日期转换@DateTimeFormat

    作者:ssslinppp       1. 摘要 本文主要讲解Spring mvc数据格式化的具体步骤: 并讲解前台日期格式如何转换为java对象: 在之前的文章<[Spring学习笔记-MVC ...

  3. ASP.NET Web Pages:C# 和 VB 实例

    ylbtech-.Net-ASP.NET Web Pages:C# 和 VB 实例 1.返回顶部 1. ASP.NET Web Pages - C# 和 VB 实例 通过 C# 和 Visual Ba ...

  4. (转!)大话websocket

    邪正看眼鼻,真假看嘴唇,功名看气概,富贵看精神. ---曾国藩<冰鉴> 转自https://www.cnblogs.com/fuqiang88/p/5956363.html 原文http: ...

  5. CentOS 6.2图形界面允许root用户登录

    测试环境中,很多操作需要root用户权限,为了提高测试效率,因此有时希望直接使用root用户登陆系统,但是CentOS的图形界面默认不允许root用户登陆,这是由于pam的限制,需要进行如下设定: 1 ...

  6. 触屏设备上的多点触碰检测C++代码实现

    转自:http://aigo.iteye.com/blog/2272698 代码还是参考自Epic官方的塔防项目:StrategyGame 看了下C++的API,现成的API中貌似只支持单点触碰检测, ...

  7. javascript的冻结对象之freeze(),isFrozen()方法

    最严格的对象保护措施就是冻结对象了.冻结过后的对象,即不可以扩展,原有对象也不可以删除,因为[Writable]=false,所以对象的属性不可修改. 示例一: var person={name:&q ...

  8. Ubuntu14.04配置jdk1.8.0_25,可切换版本

    下载jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 解压: sudo m ...

  9. Maven 添加jdk编译插件

    问题描述: 默认情况下,eclipse的maven项目使用jdk1.5编译,而我们的jdk为1.8每次更改jdk1.5之后,只要maven项目已更新,eclipse就会自动的回到jdk1.8结局方法: ...

  10. OPatch failed with error code 73(OracleHomeInventory gets null oracleHomeInfo)

    OPatch failed with error code 73(OracleHomeInventory gets null oracleHomeInfo) 1.问题描述 [oracle@dou_ra ...