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 ?
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.
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.