コード例 #1
0
ファイル: MainForm.cs プロジェクト: Smorkster/MyContacts
        /// <summary>
        /// Open form to create new contact 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void menuNewContact_Click(object sender, EventArgs e)
        {
            ContactForm nw = new ContactForm(ref contactlist);
            DialogResult nwResult = nw.ShowDialog(this);

            if (nwResult == DialogResult.OK) {
                contactlist.addcontact(nw.getContact());
                ListViewItem l = new ListViewItem(new [] {
                    nw.getContact().Name,
                    nw.getContact().Id,
                    nw.getContact().TelNrPriv,
                    nw.getContact().TelNrWork,
                    nw.getContact().MailPriv,
                    nw.getContact().MailWork
                });
                listContacts.Items.Add(l);
            }
            resizeListView();
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Smorkster/MyContacts
        /// <summary>
        /// When a listitem is doubleclicked, open form to update contact 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void listContacts_DoubleClick(object sender, EventArgs e)
        {
            ListViewItem lvi = listContacts.SelectedItems[0];
            string[] contact = new string[4];
            Contact oldContactInfo = new Contact(lvi.SubItems[0].Text, lvi.SubItems[1].Text, lvi.SubItems[2].Text, lvi.SubItems[3].Text, lvi.SubItems[4].Text, lvi.SubItems[5].Text);
            ContactForm tempNewContact = new ContactForm(oldContactInfo, ref contactlist);
            DialogResult update = tempNewContact.ShowDialog(this);

            if (update == DialogResult.OK) {
                contactlist.updatecontact(oldContactInfo.Id, tempNewContact.getContact());
                lvi.SubItems[0].Text = tempNewContact.getContact().Name;
                lvi.SubItems[1].Text = tempNewContact.getContact().Id;
                lvi.SubItems[2].Text = tempNewContact.getContact().TelNrPriv;
                lvi.SubItems[3].Text = tempNewContact.getContact().TelNrWork;
                lvi.SubItems[4].Text = tempNewContact.getContact().MailPriv;
                lvi.SubItems[5].Text = tempNewContact.getContact().MailWork;
            }
            resizeListView();
        }