Checklistbox - Select only one record

Asked

Viewed 1,129 times

1

The TCheckListBox allows selecting several items, but unlike some components let’s say "his relatives" owns the property Boolean Multiselect.

inserir a descrição da imagem aqui

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

  • Utilize Tradiogroup

  • @Eprogrammernotfound then friend. I need to use this damned. I’m going to do some tests with the ID...

2 answers

2


Sharing with Delphi Peers!

After several searches, the only option was to implement the event OnClickCheck component, 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;

Was 100% without disturbing the functioning of the component!

If you need to activate just go to the event OnClickCheck to proceed MultiSelect, to remove pass Nil.

1

No, the checklistbox has already been developed to select more than one record.

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.');
  • thanks for the strength in the resolution, I already used something similar, the boring was always send this notification! Follow my answer with the perfect solution for this!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.