예제 #1
0
        /// <summary>
        /// Populates input fields with data of the selected item in the list view.
        /// </summary>
        private void RecipesListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (RecipesListView.SelectedItems.Count != 0)
            {
                // get the selected item
                var selectedRecipe = RecipesListView.SelectedItems[0];  // multiselect is disabled. there is only one selected item

                // populate inputs
                RecipeTitleTextBox.Text         = selectedRecipe.SubItems[0].Text;
                TimeNumericUpDown.Value         = int.Parse(selectedRecipe.SubItems[1].Text);
                DifficultyComboBox.SelectedItem = selectedRecipe.SubItems[2].Text;

                CategoryCheckedListBox.ClearSelected();
                string[] selectedCategories = selectedRecipe.SubItems[3].Text.Split(new string[] { ", " }, StringSplitOptions.None);
                foreach (string selectedCategory in selectedCategories)
                {
                    int choiceIndex = CategoryCheckedListBox.Items.IndexOf(selectedCategory);
                    if (choiceIndex != -1)
                    {
                        CategoryCheckedListBox.SetItemChecked(choiceIndex, true);
                    }
                }
            }
        }