Solved

How Do Delete The Checked Items of a TCheckListBox

Posted on 1999-01-13
8
237 Views
Last Modified: 2010-05-18
How To Check Which are the Checked Items and remove them
within my TListCheckBox
0
Comment
Question by:k6__
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1356407
CheckListBox.Checked[CheckListBox.ItemIndex] := true;

-Viktor
--Ivanov
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1356408
hi k6__,

procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
  i := 0;
  while i < checklistbox1.Items.Count -1 do
  begin
    If Checklistbox1.Checked[i] then
    begin
      Checklistbox1.Items.Delete(i);
      dec(i);
    end;
    inc(i);
  end;
end;

meikl
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1356409
of this:

var i: integer;
begin
  for i := CheckBox1.Items.Count - 1 downto 0 do
    if CheckBox1.Checked[i] then
      CheckBox1.Items.Delete(i);
end;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:viktornet
ID: 1356410
oh you asked to remove them if they are checked??

ok, then philip's solution would be the best...

for i := CheckBox.Items.Count - 1 downto 0 do
  if checkbox.checked[i] then
    checkbox.items.delete(i);

that would be the solution...
0
 
LVL 2

Author Comment

by:k6__
ID: 1356411
None of the solutions worked..

i got list out of bounds or it doesn't delete the last checked
item.. etc

any ideas ?
0
 
LVL 10

Accepted Solution

by:
viktornet earned 20 total points
ID: 1356412
OK, i tested it and here is what I got...

I've got a TCheckListBox and two buttons... under one of the button's OnClick() I've got this code to add the number from 1 to 10 in the listbox...

var
  i : integer;
begin
  for i := 1 to 10 do
    LB.Items.Add(IntToStr(i));
end;

then I might check a few of them or all of them and then I use this code in the second button's OnClick() so it deletes all the checked items...

var
  i : integer;
begin
  for i := LB.Items.Count - 1 downto 0 do
    if LB.Checked[i] then
      LB.Items.Delete(i);
end;

Everything works as it should...

If you didn't copy and paste the code you might have missed the COunt - 1 or you might have done it for i := 0 to List.Items.Count - 1 which will occur also in Out Of Bounds because if you have 10 items and delete 1 then there would not ba an item 10 when the FOR loop gets to there...

Try copying and pasting the code and everything should work fine....

we use DOWNTO and not TO in the for loop so it doesn't give OUt oF Bounds...

-Viktor
--Ivanov
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1356413
hi k6__,

sorry a little mistake of my comment in the line

  while i < checklistbox1.Items.Count  - 1 do

should be

  while i < checklistbox1.Items.Count  do


procedure TForm1.Button1Click(Sender: TObject);
  var i : integer;
begin
  i := 0;
  while i < checklistbox1.Items.Count  do
  begin
    If Checklistbox1.Checked[i] then
    begin
      Checklistbox1.Items.Delete(i);
      dec(i);
    end;
    inc(i);
  end;
end;

Then its works perfectly

meikl

0
 
LVL 2

Author Comment

by:k6__
ID: 1356414
Yup =) Works !

Thanx

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 202
Reconfigure Delphi Install? 2 65
JAudiorecorder record freezing the app 29 83
Typecasting TBytes to Integer in Delphi XE8 2 35
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question