Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to take advantage of ListBox.ValueMember
Message
De
31/03/2007 21:18:48
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01209815
Message ID:
01210899
Vues:
20
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)
{
   // now you can process withoug getting an error
}
~~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
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform