Example #1
0
 private void btnFavoriteSave_Click(object sender, EventArgs e)
 {
     try
     {
         string       k    = txtFavoriteName.Text.Trim();
         string       v    = txtFavoriteRe.Text;
         FavoriteItem item = Fav.Items.FirstOrDefault(q => q.Name == k);
         if (item != null)
         {
             DialogResult result = MessageBox.Show("Name already exists. Overvrite?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
             if (result == System.Windows.Forms.DialogResult.Yes)
             {
                 item.Value = v;
                 //Favorites.Save(Fav);
                 this.DialogResult = System.Windows.Forms.DialogResult.OK;
                 this.Close();
             }
         }
         else
         {
             Fav.Items.Add(new FavoriteItem(k, v));
             //Favorites.Save(Fav);
             this.DialogResult = System.Windows.Forms.DialogResult.OK;
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public void SetItemValue(string key, string value)
        {
            FavoriteItem item = Items.FirstOrDefault(q => q.Value == key);

            if (item == null)
            {
                throw new ArgumentException();
            }
            else
            {
                item.Value = value;
            }
        }
        public string GetItemValue(string key)
        {
            FavoriteItem item = Items.FirstOrDefault(q => q.Value == key);

            if (item == null)
            {
                return("");
            }
            else
            {
                return(item.Value);
            }
        }
 public FavoriteItem(FavoriteItem item)
 {
     this.Name  = item.Name;
     this.Value = item.Value;
 }