예제 #1
0
        private void menuEditFavorite_Click(object sender, EventArgs e)
        {
            EditFavorite favEditForm = new EditFavorite();

            // 現在のお気に入りを編集用リストに格納する
            favEditForm.listView1.Items.Clear();

            foreach (Favorit fav in collectionFavorit)
            {
                ListViewItem lvitem = new ListViewItem();
                lvitem.Text = fav.title;
                lvitem.SubItems.Add(fav.address);
                favEditForm.listView1.Items.Add(lvitem);
            }

            DialogResult res = favEditForm.ShowDialog();

            if (res == DialogResult.OK)
            {
                // お気に入り配列をクリアする
                collectionFavorit.Clear();

                // お気に入り配列を再構築する
                for (int i = 0; favEditForm.listView1.Items.Count > i; i++)
                {
                    Favorit fav = new Favorit(favEditForm.listView1.Items[i].Text, favEditForm.listView1.Items[i].SubItems[1].Text);
                    collectionFavorit.Add(fav);
                }

                // お気に入りメニューを一度削除
                int itemCount = menuFavorit.DropDownItems.Count - 1;

                do
                {
                    menuFavorit.DropDownItems.RemoveAt(itemCount);
                    itemCount--;
                } while (itemCount > 2);

                foreach (Favorit fav in collectionFavorit)
                {
                    ToolStripMenuItem favitem = new ToolStripMenuItem();
                    favitem.Text        = fav.title;
                    favitem.ToolTipText = fav.address;
                    menuFavorit.DropDownItems.Add(favitem);
                }

                if (menuFavorit.DropDownItems.Count <= 3)
                {
                    toolStripSeparator4.Visible = false;
                    menuEditFavorite.Enabled    = false;
                }
            }
        }
예제 #2
0
        private void menuEditFavorite_Click(object sender, EventArgs e)
        {
            EditFavorite favEditForm = new EditFavorite();

            // 現在のお気に入りを編集用リストに格納する
            favEditForm.listView1.Items.Clear();

            foreach (Favorit fav in collectionFavorit) {
                ListViewItem lvitem = new ListViewItem();
                lvitem.Text = fav.title;
                lvitem.SubItems.Add(fav.address);
                favEditForm.listView1.Items.Add(lvitem);
            }

            DialogResult res = favEditForm.ShowDialog();

            if (res == DialogResult.OK) {
                // お気に入り配列をクリアする
                collectionFavorit.Clear();

                // お気に入り配列を再構築する
                for (int i = 0; favEditForm.listView1.Items.Count > i; i++) {
                    Favorit fav = new Favorit(favEditForm.listView1.Items[i].Text, favEditForm.listView1.Items[i].SubItems[1].Text);
                    collectionFavorit.Add(fav);
                }

                // お気に入りメニューを一度削除
                int itemCount = menuFavorit.DropDownItems.Count - 1;

                do {
                    menuFavorit.DropDownItems.RemoveAt(itemCount);
                    itemCount--;
                } while (itemCount > 2);

                foreach (Favorit fav in collectionFavorit) {
                    ToolStripMenuItem favitem = new ToolStripMenuItem();
                    favitem.Text = fav.title;
                    favitem.ToolTipText = fav.address;
                    menuFavorit.DropDownItems.Add(favitem);
                }

                if (menuFavorit.DropDownItems.Count <= 3) {
                    toolStripSeparator4.Visible = false;
                    menuEditFavorite.Enabled = false;
                }
            }
        }