TCheckListBox get count checked item

2.9k Views Asked by At

I have a simple question. How to get the count of checked item in CheckBoxListBox without using a loop?

3

There are 3 best solutions below

0
On BEST ANSWER

TCheckListBox does not provide the option that you are looking for. A loop through its Checked[] property is required.

If you were using Delphi, you could create a class helper to hide that loop. But class helpers are not available in C++.

2
On

In Delphi you can [*] do the following:

TCustomMultiSelectListControl(TheBox).MultiSelect := True;

and then SelCount works:

CountOfCheckedItems := TheBox.SelCount;

Isn't the equivalent possible in C++?

[*] Although it causes other problems.

1
On

you can use a function like this.

function GetCheckedCount(CH:TCheckListBox):Integer;
var I:Integer;
begin
   Result := 0;
    for i := 0 to ch.Items.Count - 1 do
      if ch.Checked[i] then inc(result);
end;

Also, SelCount is the number of "selected" items when MultiSelect is true ,Not number of "Checked" items