public EditMeal(IndexMeal indexMeal, Model.Meal meal) { this.indexMeal = indexMeal; _meal = meal; InitializeComponent(); label1.Text = _meal.Name; foreach (var category in Context.Categories) { checkedListBox1.Items.Add(category.Name); } var categoriesForMeal = (from r in Context.Relations join c in Context.Categories on r.CategoryId equals c.Id where r.MealId == _meal.Id select c); foreach (var category in categoriesForMeal) { for (int i = 0; i < checkedListBox1.Items.Count; i++) { if ((string)checkedListBox1.Items[i] == category.Name) { checkedListBox1.SetItemChecked(i, true); } } } }
private void indexToolStripMenuItem_Click(object sender, EventArgs e) { Form indexMeals = new IndexMeal(this); indexMeals.Focus(); indexMeals.ShowDialog(); }