Listbox sort order changed after messagebox

  • Thread starter Thread starter Roland Riess
  • Start date Start date
R

Roland Riess

Hi all,

did somebody have this problem before and found a solution?

A while ago I already found that when I display a message box (asking to
confirm the deletion of the item) after having selected an item in a
list box and clicked a button, the selected index is reset to -1 after
returning to the form with the list box. So I stored the index in a
variable before displaying the message box and reset the selected index
to the stored value afterwards.

But from time to time other items than the selected one had vanished and
having a closer look now I found that (at least sometimes) the indexes
of the list box items had changed after returning from the message box.

This seems an extremely strange behaviour to me but I could not find any
hints in the Google archives concerning this phenomenon. Somebody ever
experienced or heard of this problem? Any ideas are welcome ...

Thanks.
Regards
Roland
 
I don't believe it's possible on its own. You must be seeing interference
frm some other part of your own code
 
Hi Alex,

thanks for your answer, you helped me seeing things clearer again.
I don't believe it's possible on its own. You must be seeing
interference frm some other part of your own code
Well, at least in part you are right, as I had forgotten that I resort
the listbox elements in an ArrayList whenever the dialog is activated
(there is a Dialog_Activated handler where this is done), so e.g. after
having displayed a message box. This is the reason why my index always
"gets lost" after a message box - just a trap of my own!

But I still wonder why the sort results in a different order then
without any changes having been made to the list. And somewhat strange:
after adding another call to the sorting routine the initial order is
reestablished!

Anyway, I think I will remove the resorting from the Activated handler
and call the routine explicitly where it is needed. Like that I avoid
sorting and resorting multiple times only because a warning is displayed
before taking some action.

Regards
Roland
 
Back
Top