Pregunta

Hello i need a help with my code here Im really confused about this error, i want to pass the value from textBox1 (form 1) to textBox7 (form 2). and it said NullReferenceException was unhandled

Form 1

private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            textBox1.Text = setIDtruk.getText;
            this.Close();
        }
        catch(Exception)
        {

            MessageBox.Show("Wrong");

        }
    }

Form 2

public string getText 
    {

        get
        {
            return textBox7.Text; // error in this statement
        }

    }

can anybody help me out ? thanks

No hay solución correcta

Otros consejos

If you get a NullReferenceException on the line you indicate then the only reason that I can see is that testBox7 is null. We can't really tell you why it's null from the information that you've provided.

If it says NullReferenceException was unhandled it's probably because your TextBox7 is null. You might need to go through your code and see where you missed a declaration.

If having a null TextBox is part of your code logic, in that case instead of returning the textBox7.Text directly, test it for null and if it is (null) return the appropriate value instead (like an empty string).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top