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 ...
随机推荐
- ask 调用时间标签
织梦时间调用标签大全(2012-08-03 12:50:13) 转载▼ 分类: 织梦 织梦首页时间标签1,11-20 样式([field:pubdate function='strftime(& ...
- java 装饰设计模式模式
对已有功能进行增强 示例 已有的类 调用 增强后的类 调用 思考? 为什么要这么做呢? SuperPerson 继承 Person 可以达到同样的效果. 继承的写法,其中MyBuffer... ...
- bzoj3631 松鼠的新家
Description 松鼠的新家是一棵树,前几天刚刚装修了新家,新家有n个房间,并且有n-1根树枝连接,每个房间都可以相互到达,且俩个房间之间的路线都是唯一的.天哪,他居然真的住在“树”上.松鼠想邀 ...
- shell打印彩色输出
字体颜色(8种,3开头) 重置=0,黑色=30,红色=31,绿色=32, 黄色=33,蓝色=34, 洋红=35, 青色=36, 白色=37. 背景颜色(8种,4开头) 重置=0,黑色=40,红色=41 ...
- 廖雪峰Java1-2程序基础-5浮点数运算
1.浮点数运算的特点 很多浮点数无法精确表示 计算有误差 整型可以自动提升到浮点型 如0.1用二进制表示会是一个无限循环的小数.计算机不可能在有限内存中表示一个无限小数.因此浮点数不能精确表示.也造成 ...
- python&pandas 与mysql 连接
1. python 与mysql 连接及操作,直接上代码,简单直接高效: import MySQLdb try: conn = MySQLdb.connect(host='localhost',use ...
- jQuery 的noConflict()的使用.
我们项目现在需要用到两个js库.一个是jQuery库,还有一个是我们自己开发的轻量级的gys.js库. 而gys库对外提供的接口也是$符号.和jQuery库是一样的,这个时候,两个库就会发生冲突了,我 ...
- QT按键(Qbutton)改变颜色
第一种是按键上面的字颜色的改变: ui->motor1->setStyleSheet("color: red"); 效果: 第二种是背景改变: ui->mot ...
- 类继承-super, 私有变量
多继承 class A: def ces(self): print('a-ces') class B(A): def ces(self): print('b-ces') class C(A): def ...
- [Flutter] 支持描边效果的Text
新版的flutter已经自带这个功能了.TextSyle 中一个shadow . 目前flutter中没找到很好的办法给Text增加描边.自己扩展了一个TextEx,可以实现简单的描边效果,能满足大部 ...