2

I'm trying to send a string from form2 to form3 to pre-load the form with info. I call a method on form3 accepting the string which starts a linq query to set the controls on the form. I get a NullReferenceException was unhandled in the first foreach on recipeNameTextBox.Text = a.RecipeName; I can see that the query ran and the info is in a.RecipName. I think I might be getting this error because the control hasn't been drawn yet. Any Ideas how to get around this? Form2 code is here:

 private void updateButton_Click(object sender, EventArgs e)
 {
     Form3 Frm3 = new Form3();
     Frm3.Show();

     this.Hide();
     Frm3.takeInputFromForm2(recipeLabel.Text);
}

form3 code here:

 public void takeInputFromForm2(string incommingUpdateRecipe)
 {
     Query updateRecipe = new Query();
     IEnumerable<Recipe> newrecipe = updateRecipe.getRecipeInfo(incommingUpdateRecipe);
     foreach (var a in newrecipe)
     {
         recipeNameTextBox.Text = a.RecipeName;
         nationalityTextBox.Text = a.Nationality;
         eventTextBox.Text = a.Event;
         sourceTextBox.Text = a.Source;
         typeTextBox.Text = a.Type;
         ServingsTextBox.Text = a.Servings;
    }
    foreach (var b in newrecipe)
    {
        userRatingTextBox.Text = Convert.ToString(b.UserRating);
        familyRatingTextBox.Text = Convert.ToString(b.FamilyRating);
        healthRatingTextBox.Text = Convert.ToString(b.HealthRating);
        easeOfCookingTextBox.Text = Convert.ToString(b.CookingTime);
        cookingTimeTextBox.Text = Convert.ToString(b.CookingTime);
    }
    foreach (var c in newrecipe)
    {
        ingredientComboBox.Items.Add(c.RecipeIngredient);
    }
}
1
  • Are you missing the InitializeComponent in your Form3 constructor? Commented Oct 21, 2012 at 22:59

1 Answer 1

3

You are probably missing the InitializeComponent in your Form3 constructor.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.