コード例 #1
0
        /// <summary>
        /// Creates a dialog to add a new course to the list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddCourseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Sets general dialog properties to enter a new course
            GetOneFieldDialog courseDialog = new GetOneFieldDialog("Enter course", "Course: ", "Add");
            DialogResult      result       = courseDialog.ShowDialog();

            // Adds to the list if result is ok
            if (result == DialogResult.OK)
            {
                newCourseList.Add(courseDialog.Value);
                courseListListBox.Items.Add(courseDialog.Value);
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: tnabdall/contactManager
        /// <summary>
        /// Allows us to search contacts by last name. Selects all contacts that match.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LastNameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Opens new modal dialog to get last name
            GetOneFieldDialog dialog = new GetOneFieldDialog("Enter last name", "Last Name", "Search", "Cancel", Validation.IsNotEmptyOrNull);
            DialogResult      result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                // Go through all contacts and selects those that have the same last name as the dialog retrieved value
                for (int i = 0; i < contactsList.Count; i++)
                {
                    if (contactsList[i].LastName.ToUpper().Equals(dialog.Value.ToUpper()))
                    {
                        contactsListBox.SetSelected(i, true);
                    }
                    else
                    {
                        contactsListBox.SetSelected(i, false);
                    }
                }
            }
        }