TLama

Untitled

Apr 12th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.14 KB | None | 0 0
  1. procedure TForm1.ListViewCheckStateChanging(Sender: TObject; Item: TListItem; ToBeChecked: Boolean;
  2.   var AllowChange: Boolean);
  3. var
  4.   I: Integer;
  5. begin
  6.   // detach this event handler
  7.   ListView1.OnCheckStateChanging := nil;
  8.   try
  9.     // iterate all the items unless we find a checked one
  10.     for I := 0 to ListView1.Items.Count - 1 do
  11.       // we have found a checked item, so...
  12.       if ListView1.Items[I].Checked then
  13.       begin
  14.         // allow changing only when index of the item to be changed
  15.         // differs from the currently iterated one; that is here to
  16.         // prevent unchecking an already checked item
  17.         AllowChange := Item.Index <> I;
  18.         // if the change is allowed; it means this iterated item is
  19.         // checked and it's not the one which is going to be changed,
  20.         // uncheck it
  21.         if AllowChange then
  22.           ListView1.Items[I].Checked := False;
  23.         // and break the loop since we don't have more than 1 checked
  24.         // item
  25.         Break;
  26.       end;
  27.   finally
  28.     // finally re-attach the event handler
  29.     ListView1.OnCheckStateChanging := ListViewCheckStateChanging;
  30.   end;
  31. end;
Advertisement
Add Comment
Please, Sign In to add comment