Why is combobox_SelectedIndexChanged() invoked when exiting my application?

I have a combobox and use the selectedindexchange event.

But every time i close my application, i will get the following error in the code inside my selectedindexchanged event:

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."

I don't understand why this code is run when i close my application I have not created any events for closing or something like that...



Answer this question

Why is combobox_SelectedIndexChanged() invoked when exiting my application?

  • Mr_Z

    Is your ComboBox databound What's the code in your SelectedIndexChanged event

    The SelectedIndexChanged event fires a lot of times when the combo is instantiated, loaded, etc. ... sometimes you just have to code around it.



  • Peter Peng

    Nobody have any idea

    It's very frustrating since i can't find any logical reason to why this event would fire when a form is closed! The control isn't even active... (selected)


  • ephisians

     BonnieB wrote:

    Is your ComboBox databound What's the code in your SelectedIndexChanged event

    Yes, it's databound. Is that the problem That when a form is closed, theres "background-activity" with the datasources

    The code in the event is a single TableAdapter.Fill(..) , and i guess i could fix the error,  but i'm just curious why the event fires, and if theres anyway i could prevent that - instead of make a workaround in the event handler.


  • hazz

    I've never tried that event ... hmmm, maybe I should play around with it.

    I also haven't used TableAdapters (they are new to 2.0 and I've been doing this since 1.0) ... so, who knows if *that* has anything to do with it.



  • lois_at_DEI

    I solved the problem by using the SelectionChangeCommitted event instead.

    It could still be interesting to know the answere to the original question though, if anyone knows :)


  • Why is combobox_SelectedIndexChanged() invoked when exiting my application?