Simulate an OnCheck event for TListView checkboxes (Views: 28)
Problem/Question/Abstract: I am working on a program that uses a TListView with the checkboxes property set to true. There are several things I would like to be triggered off of the boxes being checked or unchecked. Is there any OnCheck event or something similar that I can use to start a process off of the check of one of these boxes? Answer: It seems, there isn't such event. But you could use this workaround: procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var li: TListItem; ht: THitTests; begin if ListView1.Items.Count <= 0 then exit; li := ListView1.GetItemAt(x, y); if Li <> nil then begin if li.Selected = false then li.Selected := true; end else exit; ht := LVSoLine.GetHitTestInfoAt(x, y); if ht = [htOnStateIcon] then begin { Write your code here for checkbox OnCheck event. Remember this will fire after the checkbox state is changed } end; end; |