On Fri, 21 Oct 2005 12:53:43 +0200, "Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote:
"John Veldthuis" <jo***@no.spamo .paradise.net.n z> schrieb: My code works perfectly 100% when adding items to my ArrayList and
updating the listbox.
Works perfectly when deleting an item in the ArrayList when it is not the
last entry but if it is
the last entry and you select another index it goes boom!!!.
Funny thing is the SelectedIndex Changed routine fires off perfectly and
then crash after the return
from this code.
How are you binding the items of the arraylist to the listbox control? How
do you update the listbox control? I suggest to post some code.
dim ch1recipes as clsRecipes
file in the array here by loading from an SQL database.
for the listbox to display I simply set the datasource
lbRecipes.DataS ource = ch1recipes
The class for ch1recipes has an override on the ToString method to display a full name. Everything
working fine to here.
Next remove the item if the user selects it and clicks the delete button.
lbRecipe.DataSo urce = Nothing
ch1recipes.Remo ve(lbRecipe.Sel ectedIndex) ' This removes the data from the ArrayList
' Remove the data from the SQL Database here
lbRecipe.DataSo urce = ch1recipes ' Needed to remove and add so that display is updated properly
Now everything works fine unless the item selected in the listbox is the last one. All the code
works fine. The item is removed properly from the arraylist and removed from the SQL database.
If it is the last one then as soon as the SelectedIndex method exits the subroutine it crashes. It
does not crash in user code so cannot be de-bugged.
Searching through the Google News I found several messages about exactly the same thing around 2002
and it was identified as a bug and reproducable 100% of the time. There was one suggetion as a work
around and that was to select the previous item in the listbox via code before removing the last
item in the arraylist. I tried this and it does cure the problem but is only a messy work around.