# WebListBox SelCount

**URL:** <https://forum.xojo.com/t/weblistbox-selcount/43556>\
**Category:** General\
**Created:** [May 17, 2018, 6:52pm UTC](https://forum.xojo.com/t/weblistbox-selcount/43556 "2018-05-17T18:52:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anthony\_Mott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@Anthony\_Mott](https://forum.xojo.com/u/Anthony_Mott)\
**Post date:** [May 17, 2018, 6:52pm UTC](https://forum.xojo.com/t/weblistbox-selcount/43556/1 "2018-05-17T18:52:16Z")

</div>

I hope I’m missing something but how can I tell the number of selected items in a WebListBox without having to cycle through the entire list? On a standard ListBox I can us the SelCount property but that doesn’t seem to exist in the web version.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [May 17, 2018, 7:08pm UTC](https://forum.xojo.com/t/weblistbox-selcount/43556/2 "2018-05-17T19:08:08Z")

</div>

You do have to cycle through and count the selected(). Nothing prevents you for throwing that into a selcount method, though 🙂

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [May 18, 2018, 8:20am UTC](https://forum.xojo.com/t/weblistbox-selcount/43556/3 "2018-05-18T08:20:49Z")

</div>

Here is one I wrote ages ago for both desktop and web apps. The desktop side is redundant!

[code]Protected Function getListBoxSelectedCountWAD(myListBox As Object) as Integer  
'returns the total number of rows that are selected in the provided ListBox  
Dim selectedRows As Integer 'used by Desktop/Web

if myListBox = nil then Return 0

#if TargetDesktop then  
Dim tempListBox As ListBox  
if myListBox IsA Listbox then tempListBox = ListBox(myListBox)

```
if tempListBox.ListIndex < 0 then Return 0

for tempInt As Integer = 0 to tempListBox.ListCount - 1
  if tempListBox.Selected(tempInt) then selectedRows = selectedRows + 1
next

Return selectedRows

```

#elseif TargetWeb then  
Dim tempWebListBox As WebListBox

```
if myListBox IsA WebListBox then tempWebListBox = WebListBox(myListBox)

if tempWebListBox.ListIndex < 0 then Return 0

for tempInt As Integer = 0 to tempWebListBox.RowCount - 1
  if tempWebListBox.Selected(tempInt) then selectedRows = selectedRows + 1
next

Return selectedRows

```

#endif

End Function[/code]

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:13pm UTC](https://forum.xojo.com/t/weblistbox-selcount/43556/4 "2020-10-29T19:13:09Z")

</div>


