Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. List<Controls> list = new List<Controls>
  2.  
  3. myObject.myList.Add(new Control());
  4.  
  5. myList.AddingEvent += HandleAddingEvent
  6.  
  7. using System;
  8. using System.Collections.Generic;
  9.  
  10. namespace test {
  11. class Program {
  12.  
  13. class MyList<T> : List<T> {
  14.  
  15. public event EventHandler OnAdd;
  16.  
  17. public void Add(T item) {
  18. if (null != OnAdd) {
  19. OnAdd(this, null);
  20. }
  21. base.Add(item);
  22. }
  23.  
  24. }
  25.  
  26. static void Main(string[] args) {
  27. MyList<int> l = new MyList<int>();
  28. l.OnAdd += new EventHandler(l_OnAdd);
  29. l.Add(1);
  30. }
  31.  
  32. static void l_OnAdd(object sender, EventArgs e) {
  33. Console.WriteLine("Element added...");
  34. }
  35. }
  36. }
  37.  
  38. ObservableCollection<int> myList = new ObservableCollection<int>();
  39.  
  40. myList.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(
  41. delegate(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  42. {
  43. if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
  44. {
  45. MessageBox.Show("Added value");
  46. }
  47. }
  48. );
  49.  
  50. myList.Add(1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement