0

I can't get value from form2 combobox. I checked that combobox modifier set to 'Public'.

I get the 'Object not referenced to instance of a object' error. What is the mistake?

//Form1
private DialogIO dio;

private void uosIO_ValueChanged(object sender, EventArgs e)
{
   dio = new DialogIO();
   dio.Show(); // Open Form2 and Set Some value on Combobox
}


// BGWorker get run call from form2 and run it on form1.
private void bgwCustomIO_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
   MessageBox.Show(dio.uceMinHour.Text); // Show Combobox Value
}
john true
  • 263
  • 1
  • 5
  • 26

1 Answers1

0

consider check for null also...

 private void bgwCustomIO_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
    {
        if (dio == null || string.IsNullOrEmpty(dio.uceMinHour.Text))
        {
            return;
        }
       MessageBox.Show(dio.uceMinHour.Text); // Show Combobox Value
    }
Manish Dubey
  • 706
  • 4
  • 17