Opened 11 years ago

Closed 10 years ago

#3720 closed defect (fixed)

wxVListBox/wxHtmlListBox: GetSelection after SetItemCount

Reported by: belgabor Owned by:
Priority: normal Milestone:
Component: GUI-generic Version:
Keywords: wxVListBox Cc: belgabor
Blocked By: Blocking:
Patch: yes



I found a bug in wxHtmlListBox, but I suspect it goes down to wxVListBox. If you call SetItemCount and reduce the number of items, the current selection is not sanity-checked, so if you call GetSelection before user interaction with the control, it is possible that the index you get back is illegal.
The control should check on SetItemCount whether the currently selected item index is still < item count and either set it to the max or wxNOT_FOUND (-1) if not.

(Checked against current CVS Head)

Attachments (1)

vlbox-setcount.diff download (347 bytes) - added by wojdyr 10 years ago.

Download all attachments as: .zip

Change History (3)

Changed 10 years ago by wojdyr

comment:1 Changed 10 years ago by wojdyr

  • Component changed from base to GUI-generic
  • Keywords wxVListBox added
  • Patch set

blind fix is attached

comment:2 Changed 10 years ago by vadz

  • Resolution set to fixed
  • Status changed from new to closed

I prefer to set m_current to the last valid index if its old value became invalid as this is what you want to do if you use SetItemCount() to delete the last item(s).

But other than that this indeed seems the right thing to do, thanks, applied to both brancehs in r53998.

Note: See TracTickets for help on using tickets.