ちょいメモ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
class Person { public string Name; public int Age; } public partial class Form1 : Form { public Form1() { InitializeComponent(); ObservableCollection<Person> peoples = new ObservableCollection<Person>(); peoples.Add(new Person { Name = "taro", Age = 1 }); peoples.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Notify); //値の変更では反応しない。 peoples[0].Name = "taro3"; //ここで反応 peoples.Add(new Person { Name = "jiro", Age = 2 }); } private void Notify(object sender, EventArgs e) { MessageBox.Show(""); } } |