[Mono-winforms-list] NullReferenceException on SelectedValueChanged

Pavel Bansky levap at bansky.net
Sat Jul 7 13:20:17 EDT 2007


Hello Jon,

did you try this?

private void SelectedValueChangedEvent(object sender, EventArgs e)
{
   lstBox = (ListBox)sender;
   string sFileName = lstBox.SelectedValue.ToString();
}

Pavel


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
> 

-- 
__________________________________________________________

Pavel Bánský
levap at bansky.net                        I write code...
__________________________________________________________


More information about the Mono-winforms-list mailing list