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 ...
随机推荐
- Tomcat 去除项目名称
再tomcat的conf下server.xml 里, 再<host>...</host>的标签之间添加 <Context path="" docBa ...
- java GUI(忽略)
觉得学起来很鸡肋.就不学这玩意了
- 【Spring学习笔记-MVC-6】SpringMVC 之@RequestBody 接收Json数组对象
作者:ssslinppp 1. 摘要 程序流程: 前台使用ajax技术,传递json字符串到后台: 后台使用Spring MVC注解@RequestBody 接受前台传递的json字符串, ...
- bzoj1047 理想的正方形
Description 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. Input 第一行为3个整数,分别表示a,b,n的值第二行至第 ...
- HttpUrlConnection使用详解--转
http://blog.csdn.net/fightingXia/article/details/71775516 一,HttpURLconnection的介绍 在Android开发中网络请求是最常用 ...
- ASP.NET Web Pages:文件夹
ylbtech-.Net-ASP.NET Web Pages:文件夹 1.返回顶部 1. ASP.NET Web Pages - 文件夹 本章介绍有关文件夹和文件夹路径的知识. 在本章中,您将学到: ...
- 学大伟业Day1解题报告
学大伟业Day1解题报告 张炳琪 一. 时间分配 T1:30分钟 T2: 60分钟 T3:100分钟 二.答题情况及错因 T1:100 T2:55 T3 ...
- 属性,类方法@classmethod
# 属性的初识# class Person:## def __init__(self,name,hight,weight):# self.name = name# self.__hight = hig ...
- 搭建pyspider爬虫服务
1. 环境准备 首先yum更新 yum update -y 安装开发编译工具 yum install gcc gcc-c++ -y 安装依赖库 yum install python-pip pytho ...
- 动态html处理和及其图像识别
爬虫(Spider),反爬虫(Anti-Spider),反反爬虫(Anti-Anti-Spider) 之间恢宏壮阔的斗争... Day 1 小莫想要某站上所有的电影,写了标准的爬虫(基于HttpCli ...