Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

ADO.NET 2.0 Question

Back to Forum: Tech Off
  • User profile image
    brownsoft

    Visual C# Express with SQL 2005 Express

    I am creating a data aware application but I have ran into what feels like a 'hack' to me.

    I have a form with a ComboBox which is databound to a database. The selectedValue field is mapped to a integer field in the db. So inside the SelectedIndexChanged Event when I do the following I get a null reference exception when the app closes:
      int idvalue = cmbbox.selectedValue


    I notice if I add the following I no longer get an exception:
        if (cmbbox.selectedValue != null)
              idValue = cmbbox.selectedValue

    Does this feel like a hack or is just me???  Why does selectedIndexChanged event get fired when the app closes??


  • User profile image
    Lee_Dale

    Probably becuase when the control gets destroyed all the items in the combo box get cleared therefore the selected index will change to null becuase the previously selected item has now dissapeard.

  • User profile image
    littleguru

    This is weird. I have done a lot databinding, but I never got this thing. Are you sure you are not calling or doing something that causes that behaviour?

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.