Selecting an item in a TListView when the checkbox is checked
By Corbin Dunn
Delphi Developer Support
You may have noticed some peculiar behavior with a TListView that has check boxes. Checking a check box does not select the underlying item. There is any easy way to solve this problem. In the OnMouseDown event handler of the TListView add the following code:
procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Item: TListItem;
begin
// Did we hit a checkbox? If so, make sure the item it
// represents is selected.
Item := ListView1.GetItemAt(X, Y);
if Item <> nil then
if ListView1.Selected <> Item then
ListView1.Selected := Item;
end;
This should solve that problem!
If you want some example source code with this solution in it, download the project from CodeCentral.
Last Modified: 26-MAR-01