I'd like to delete checked items from CheckListBox by cliicking TButton but I've found only how to delete selected item and it's not what I'm looking for. I hope you can help me
Deleting checked item from CheckListBox
401 Views Asked by Alicia At
2
There are 2 best solutions below
9
On
This code will do what you want. Note that CheckBoxList1.Items.Count is decreasing by one every time an item is deleted. For this reason we're using downto instead of do in the for-loop.
procedure TForm1.Button1Click(Sender: TObject);
var
index: Integer;
begin
CheckListBox1.Items.BeginUpdate;
try
for index := (CheckListBox1.Items.Count - 1) downto 0 do
if (CheckListBox1.Checked[index]) then
CheckListBox1.Items.Delete(index);
finally
CheckListBox1.Items.EndUpdate;
end;
end;
The CheckListBox1.Items.BeginUpdate; and CheckListBox1.Items.EndUpdate; statements ensure that the control doesn't repaint itself while we're processing its items.
if i understand what you need, try following code:
Of curse, there are better solutions, but it is ready to use for you.