CheckListBox - Select only one record

1

The TCheckListBox allows you to select several items, but different from some components let's say "his relatives" has the Boolean MultiSelect

Is there any function or procedure to allow only 1 selected item?

    
asked by anonymous 07.01.2016 / 17:10

2 answers

1

Sharing with Delphi Colleagues!

After several searches, the only option was to implement the component OnClickCheck event, I believe this is the only option:

procedure MultiSelect;
var
  i: Integer;
begin
  with Seu_CheckListBox do
  begin
    if (Checked[ItemIndex]) then
    begin
      Items.BeginUpdate;
      for i := 0 to Pred(Items.Count) do
      begin
        if (i <> ItemIndex) then
          Checked[i] := False;
      end;
      Items.EndUpdate;
    end;
  end;
end;

It was 100% without disturbing the Function of the component!

If you need to activate, simply pass OnClickCheck to MultiSelect to remove Nil .     

11.01.2016 / 16:48
1

No, the checklistbox has already been developed so that more than one record is selected.

If you need to work with this component and want only one record to be selected, you can perform a validation as follows

total := 0;
for i := 0 to CheckListBox1.Items.Count - 1 do
    begin

       if CheckListBox1.Checked[i] then    // se o registro estiver marcado...
          inc(total);

    end;

if total > 1 then
   ShowMessage('Atenção somente 1 registro pode ser selecionado.');
    
08.01.2016 / 13:30