Getting a listbox selected value from a seperate form RRS feed

  • Question

  • Hi all,

              I'm having a rather strange problem with listbox.selectedvalue.  I have a form (Form1) that has a listbox populated with values from a database.  I also have a button on Form1 called 'delete'.  When you select a listbox item and click delete it brings up a new dialog form (Form2) thats asks if you are sure you want to delete the selected item from the listbox/database.  You can choose 'Yes' or 'No' via two buttons on Form2.  When you click the 'Yes' button, it calls my deleteItem() subroutine from Form1 which deletes the selected listbox item (note: this code works fine and has no errors if you call it when you click 'Delete' from Form1).  The problem im having is that when i try to call my deleteitem() routine from Form2, an exception is thrown saying 'object reference is not set to the instance of an object'.  I've worked out that this is occuring because when i close Form2 there is no longer an item selected in my listbox on Form1.  It is still highlighted when you close Form2 but listbox.selectedvalue has no value anymore.  I need to somehow store the selectedvalue so i can use it in my deleteitem() subroutine or something similar.  Can anyone suggest any solutions to this problem?



    Tuesday, April 11, 2006 12:49 PM


All replies