[Mono-winforms-list] NullReferenceException on SelectedValueChanged

Jonathan Pobst monkey at jpobst.com
Sat Jul 7 13:24:07 EDT 2007

ListControl.SelectedValueChanged is sent when the value in a listbox 
changes, which may include the value being changed to nothing selected. 
  The usual way to ensure something is actually selected is to check the 
SelectedIndex, as shown in the MSDN documentation example: 

If you have a test case that fails on Mono but works on MS.Net, please 
file a bug at http://bugzilla.ximian.com/ and we'll be happy to look 
into it.


Jon Cosby wrote:
> I have this event handler for SelectedValueChanged on a ListBox:
>     private void SelectedValueChangedEvent(object sender, EventArgs e)
>     {
>         string sFilename = fileListBox.SelectedValue.ToString();
>     }
> There's a NullReferenceException at runtime,
> "System.NullReferenceException: Object reference not set to an instance
> of an object". What's up? Evidently the value has changed as it reaches
> the handler. To null? The listbox is not empty.
> Jon Cosby
> _______________________________________________
> Mono-winforms-list maillist  -  Mono-winforms-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-winforms-list

More information about the Mono-winforms-list mailing list