Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TForm1.ListViewCheckStateChanging(Sender: TObject; Item: TListItem; ToBeChecked: Boolean;
- var AllowChange: Boolean);
- var
- I: Integer;
- begin
- // detach this event handler
- ListView1.OnCheckStateChanging := nil;
- try
- // iterate all the items unless we find a checked one
- for I := 0 to ListView1.Items.Count - 1 do
- // we have found a checked item, so...
- if ListView1.Items[I].Checked then
- begin
- // allow changing only when index of the item to be changed
- // differs from the currently iterated one; that is here to
- // prevent unchecking an already checked item
- AllowChange := Item.Index <> I;
- // if the change is allowed; it means this iterated item is
- // checked and it's not the one which is going to be changed,
- // uncheck it
- if AllowChange then
- ListView1.Items[I].Checked := False;
- // and break the loop since we don't have more than 1 checked
- // item
- Break;
- end;
- finally
- // finally re-attach the event handler
- ListView1.OnCheckStateChanging := ListViewCheckStateChanging;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment