private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switchItem();
}
private void switchItem()
{
var content = richTextBox1;
switch (comboBox1.SelectedValue.ToString())
{
case "Fruit":
content.Text = "Apple";
break;
default:
content.Rtf = "Not Selected";
break;
}
}
正如您所看到的,我正在尝试获取comboBox1的SelectedValue
,并显示此object reference not set to an instance of an object
错误。我该怎么办?
答案 0 :(得分:1)
也许您正在寻找SelectedItem
而不是SelectedValue
错误object reference not set to an instance of an object
表示SelectedValue
为null