我想通過單擊 TButton 從 CheckListBox 中洗掉選中的專案,但我只找到了如何洗掉所選專案的方法,這不是我要找的。我希望你能幫幫我
uj5u.com熱心網友回復:
此代碼將執行您想要的操作。請注意,CheckBoxList1.Items.Count每次洗掉一個專案時,它都會減一。出于這個原因,我們在 for 回圈中使用downto而不是do。
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;
該CheckListBox1.Items.BeginUpdate;和CheckListBox1.Items.EndUpdate;陳述句確保在我們處理的專案控制不重繪自己。
uj5u.com熱心網友回復:
如果我了解您的需要,請嘗試以下代碼:
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
count : Integer;
begin
i:= 0;
count := CheckListBox1.Items.Count - 1;
while i <= count do
if CheckListBox1.Checked[i] = true then
begin
CheckListBox1.Items.Delete(i);
count := count - 1;
end else i:=i 1;
end;
當然,有更好的解決方案,但它已準備好供您使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/386635.html
