Speed up iterating selected rows in a desktop ListBox
- Status
- Fixed
- Fixed in
- v26.10.2
- Area
- desktop
- Source discussion
- https://forum.objo.dev/d/1295-listbox-setting-true-or-false-for-checkbox-using-code-take-time
- Last updated
- 2026-10-12
Upvotes
1 upvote
Uses your Objo forum account.
Public summary
Code that loops over the selected rows of a multi-select desktop ListBox using the natural pattern:
For i As Integer = 0 To lb.SelectedRowCount - 1
Var rowIndex As Integer = lb.SelectedRowIndex(i)
lb.SetCellChecked(rowIndex, 0, True)
Next i
becomes very slow as the row count grows, because each SelectedRowIndex(i) call re-derives the selected row indexes by scanning every row in the ListBox. With 100,000 rows, updating 5,000 selected rows takes about 12 seconds, and 10,000 selected rows takes about 29 seconds (forum-reported timings). The cost of this loop should not grow with the total number of rows.
Improve this so the natural loop is fast on large lists. No API or behaviour change is required; only the internal cost of resolving selected row indexes.
Until this ships, reading lb.SelectedRowIndexes once and looping over that array avoids the slowdown, because it resolves all selected indexes in a single pass.