Custom Dictionary Sample code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DictonaryValueChanged
{
public class ExtendedDictonary<Tkey,Tvalue> : Dictionary<Tkey,Tvalue>
{
public Dictionary<Tkey,Tvalue> Items = new Dictionary<Tkey,Tvalue>();
public ExtendedDictonary():base(){}
ExtendedDictonary(int capacity) : base(capacity) { }
public event EventHandler ValueChanged;
public void OnValueChanged(Object sender,EventArgs e)
{
EventHandler handler = ValueChanged;
if (null != handler) handler(this, EventArgs.Empty);
}
public void AddItem(TKey key, TValue value)
{
try
{
Items.Add(key, value);
OnValueChanged(this, EventArgs.Empty);
}
catch (Exception ex)
{
throw ex;
}
}
}
}
Using this Dictionary in your code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DictonaryValueChanged
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ExtendedDictonary<string,int> dicMemory = new ExtendedDictonary<string,int>();
dicMemory.ValueChanged += new EventHandler(DictonaryOnValuedChanged);
dicMemory.AddItem("Hai", 1);
}
private void DictonaryOnValuedChanged(Object sender, EventArgs e)
{
string test = sender.ToString();
}
}
}