如何在TListView标题列中显示复选框?
我需要在 TListView 的列标题中有一个复选框:
我已尝试以下代码:
with CheckBox1 do
begin
Parent := ListView1;
Top := 0;
Left := 4;
end;
但该复选框并不总是按预期工作。如何在 TListView 标题列中正确创建复选框?
I need to have a check box in a column header of a TListView:
I have tried the following code:
with CheckBox1 do
begin
Parent := ListView1;
Top := 0;
Left := 4;
end;
but the check box doesn't always work as expected. How can I properly create a check box in TListView header column ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下代码将向列表视图的标题添加复选框,并显示如何处理它的点击事件。
请注意,自 Windows Vista 起支持以下代码。
The following code will add the check box to the list view's header and shows how to handle the click event for it.
Please note, that the following code is supported since Windows Vista.
如果您的目标是 Vista 及更高版本,明显的答案是 TLama's。如果没有,请将复选框置于标题控件中,而不是列表框中(同样如 TLama 对问题的评论)。该复选框将向其父级(标题控件)发送通知,因此您需要对其进行子类化。工作示例:
请注意,如果您设置了“ColumnClick”,那么当您单击该复选框时,该复选框不会与标题按钮一起“推动”,这看起来很丑陋。
If you are targeting Vista and later, obvious answer is TLama's. If not, parent the check box in the header control, not in the list box (again as TLama commented to the question). The check box will send notifications to its parent - the header control, so you need to subclass it. Working sample:
Note that if you've 'ColumnClick' set, it looks ugly that the check box does not 'push' with the header button when you click on it.