Beispiel #1
0
        void menu_newItem_Click(object sender, EventArgs e)
        {
            int index = -1;

            if (this.listView1.SelectedIndices.Count > 0)
            {
                index = this.listView1.SelectedIndices[0];
            }

            TwoStringDialog dlg = new TwoStringDialog();

REDO:
            dlg.ShowDialog(this);
            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            ListViewItem dup = ListViewUtil.FindItem(this.listView1, dlg.SourceString, 0);

            if (dup != null)
            {
                MessageBox.Show(this, "源字符串为 '" + dlg.SourceString + "' 的事项在列表中已经存在了,不允许重复。请修改");
                goto REDO;
            }

            ListViewItem item = new ListViewItem();

            ListViewUtil.ChangeItemText(item, 0, dlg.SourceString);
            ListViewUtil.ChangeItemText(item, 1, dlg.TargetString);

            if (index == -1)
            {
                this.listView1.Items.Add(item);
            }
            else
            {
                this.listView1.Items.Insert(index, item);
            }
            ListViewUtil.ClearSelection(this.listView1);
            ListViewUtil.SelectLine(item, true);
        }
Beispiel #2
0
        void menu_modifyItem_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.listView1.SelectedItems.Count == 0)
            {
                strError = "尚未选择要修改的事项";
                goto ERROR1;
            }

            ListViewItem item = this.listView1.SelectedItems[0];

            TwoStringDialog dlg = new TwoStringDialog();

            dlg.SourceString = ListViewUtil.GetItemText(item, 0);
            dlg.TargetString = ListViewUtil.GetItemText(item, 1);
REDO:
            dlg.ShowDialog(this);
            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            ListViewItem dup = ListViewUtil.FindItem(this.listView1, dlg.SourceString, 0);

            if (dup != null && dup != item)
            {
                MessageBox.Show(this, "源字符串为 '" + dlg.SourceString + "' 的事项在列表中已经存在了,不允许重复。请修改");
                goto REDO;
            }
            ListViewUtil.ChangeItemText(item, 0, dlg.SourceString);
            ListViewUtil.ChangeItemText(item, 1, dlg.TargetString);
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }