ListBox and ComboBox are similar in that their SelectedIndexChanged and SelectedValueChanged events fire several times when you don't expect them to, such as when a form is first activated. Perhaps this also happens at other times as well (like when you're exiting). In my event handlers, I always check first that there actually *is* an item selected:
if (listBox1.SelectedIndices.Count > 0)
{
}
~~Bonnie
>But, this now leads to another error. When I exit the program, I get the following message:
>
>"Object reference not set to an instance of an object", and the line pointed to is
>
>this.SessionID = (int) listBox1.SelectedValue;
>
>In the debugger's watch list, I can see that SessionID = 76, the last thing I processed. this.listBox1 seems to still exist. But, this.listBox1.SelectedValue is null.
>
>Should I be cleaning up or something to prevent this? Or should I just check for SelectedValue not NULL before I try to use it?
>
>Thanks
>Jim