Sriram Ramki

Sriram Ramki

  • NA
  • 20
  • 4.8k

what is object reference not set to an instance of an object

Oct 31 2018 11:15 PM
In Windows Form , I Created ComboBox, when i try to Create a new name, it doesn't show any output. Instead of that it is showing " System.NullReferenceException : 'Object reference is not set to an instance of an object.
private void btnCountry_Click(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.Text);
MessageBox.Show(comboBox1.SelectedItem.ToString());MessageBox.Show(comboBox1.SelectedIndex.ToString());
this.Close();
}
private void btnStates_Click(object sender, EventArgs e)
{
foreach(object obj in listBox1.SelectedItems)
{
MessageBox.Show(obj.ToString());
}
}
 

Answers (5)