示例#1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            FormEditCourse formEditCourse = new FormEditCourse("添加课程", "课程代码", "课程名称(选填)", "备注(选填)", true);

            formEditCourse.ShowDialog();
            if (formEditCourse.res == DialogResult.OK)
            {
                ListViewItem listViewItem = new ListViewItem(formEditCourse.id.Trim());
                listViewItem.SubItems.Add(formEditCourse.name.Trim());
                listViewItem.SubItems.Add(formEditCourse.add.Trim());
                listViewItem.SubItems.Add("");
                if (listViewItem.Text.Trim().Length == 0)
                {
                    MessageBox.Show("课程名为空!");
                    return;
                }
                listViewWillChooseCourse.Items.Add(listViewItem);
            }
        }
示例#2
0
 private void buttonEdit_Click(object sender, EventArgs e)
 {
     if (listViewWillChooseCourse.SelectedItems.Count > 0)
     {
         var listViewItem   = listViewWillChooseCourse.SelectedItems[0];
         var index          = listViewWillChooseCourse.Items.IndexOf(listViewItem);
         var formEditCourse = new FormEditCourse("编辑课程", listViewItem.Text, listViewItem.SubItems[1].Text, listViewItem.SubItems[2].Text, false);
         formEditCourse.ShowDialog();
         if (formEditCourse.res == DialogResult.OK)
         {
             listViewItem = new ListViewItem(formEditCourse.id.Trim());
             listViewItem.SubItems.Add(formEditCourse.name.Trim());
             listViewItem.SubItems.Add(formEditCourse.add.Trim());
             listViewItem.SubItems.Add(listViewWillChooseCourse.Items[index].SubItems[3].Text);
             if (listViewItem.Text.Trim().Length == 0)
             {
                 MessageBox.Show("课程名为空!");
                 return;
             }
             listViewWillChooseCourse.Items[index] = listViewItem;
         }
     }
 }