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. sklearn, Numpy以及Pandas

    pandas里面的对于数据操作比如where,drop以及dropna等都会有一个属性:inplace,这个单词意思是原地,如果inplace=true代表数据本身要执行该操作:如果inplace=f ...

  2. 使用php在服务器端生成图文验证码(二)

    图文验证码的实现原理: 1):准备些许图片将其存储在数据库,每一张图片对应一个标识字段. 2):在服务器端使用数组的形式将图片与标识字段组合起来. 3):随机给客户端返回图片,并接受用户输入的字段. ...

  3. Microsoft Dynamics CRM 2013 安装 报表服务出现“ SQL Server Reporting Services 帐户是本地用户且不受支持 ”错误的解决方法

    安装好CRM 2013 之后,还需要安装报表服务,发现出现:SQL Server Reporting Services 帐户是本地用户且不受支持,具体如下图: 经过分析原来发现是需要用域用户,打开对应 ...

  4. ES(2): Build ES Cluster on Azure VM

    目录: 系统环境准备 安装ES集群 安装Kibana 安装x-pack 安装head 系统环境准备 参见: HDP2.4安装(二):Centos7配置 修改network: 修改hosts: 配置ss ...

  5. SVN同步

    SVN同步:1.在备份服务器上安装SVN,之后创建同名的库名2.在备机的Repositories的库文件夹下的hooks目录下,备份并修改pre-revprop-change.tmpl文件为pre-r ...

  6. 比较全面的MySQL优化参考(转)

    上篇:) http://imysql.com/2015/05/24/mysql-optimization-reference-1.shtml 下篇:) http://imysql.com/2015/0 ...

  7. Linux Shell脚本编程--Linux特殊符号大全

    Linux Shell脚本编程--Linux特殊符号大全 linux_shell 特殊符号的介绍 2011

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

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

  9. 【BZOJ】1257: [CQOI2007]余数之和(除法分块)

    题目 传送门:QWQ 分析 大佬和我说本题是除法分块,莫比乌斯反演中也有用到. QwQ我不会莫比乌斯反演啊~ 题目让我们求  $ \sum_{i=1}^n  k\mod n $ 然后根据$ a \mo ...

  10. PHP 算术运算符

    PHP 算术运算符 运算符 名称 描述 实例 结果 x + y 加 x 和 y 的和 2 + 2 4 x - y 减 x 和 y 的差 5 - 2 3 x * y 乘 x 和 y 的积 5 * 2 1 ...