.NET listbox Control help

Spydermag68

Platinum Member
Apr 5, 2002
2,616
99
91
I get the following error when I click on button to preform and action based on a listbox selection and nothing in the listbox has been highlighted.


Error:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 722:
Line 723:
Line 724: SelectedString += CardListBox.SelectedItem.ToString

 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
Looks like the SelectedItem is null. Either a) assign some default empty value on initialization, or b) on the action performed method check for a null value before accessing it.
 

Snapster

Diamond Member
Oct 14, 2001
3,916
0
0
So why not add some code that tests if they have selected something first, eg: