i have this case which works after data has been loaded to to the combobox and the textbox, but when the app first gets loaded and the combobox is = Tobacco Use? and trys to set the textbox to empty i get "NullReferenceException - Object reference not set to an instance of an object". not sure how to fix this and be able to keep it clearing the textbox when "Tobacco Use? " is selected. Also "Tobacco Use?" is the default on the combobox.
comboBox cbTobacco.Text
textBox = cbTobaccoCode.Text
private void cbTobacco_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cbTobacco.Text != null)
{
switch (Convert.ToString(cbTobacco.Text))
{
case "Tobacco Use?": strTobaccoCode = ""; break;
case "1 - Current every day smoker": strTobaccoCode = "449868002"; break;
case "2 - Current some day smoker": strTobaccoCode = "428041000124106"; break;
case "3 - Former smoker": strTobaccoCode = "8517006"; break;
case "4 - Never smoker": strTobaccoCode = "266919005"; break;
case "5 - Smoker, current status unknown": strTobaccoCode = "77176002"; break;
case "6 - Unknown if ever smoked": strTobaccoCode = "266927001"; break;
case "7 - Heavy tobacco smoker": strTobaccoCode = "428071000124103"; break;
case "8 - Light tobacco smoker": strTobaccoCode = "428061000124105"; break;
}
cbTobaccoCode.Text = strTobaccoCode;
}
}