private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.OldItems != null) { foreach (INotifyPropertyChanged item in e.OldItems) { _observedItems.Remove(item); item.PropertyChanged -= ItemPropertyChanged; } } if (e.NewItems != null) { foreach (INotifyPropertyChanged item in e.NewItems) { _observedItems.Add(item); item.PropertyChanged += ItemPropertyChanged; ItemChangedEventHandler handler2 = ItemChanged; handler2?.Invoke(item, null);//e = {System.ComponentModel.PropertyChangedEventArgs} } } NotifyCollectionChangedEventHandler handler = CollectionChanged; handler?.Invoke(sender, e); }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// itemchangedeventhandler.BeginInvoke(sender, e, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this ItemChangedEventHandler itemchangedeventhandler, Object sender, ItemChangedEventArgs e, AsyncCallback callback) { if (itemchangedeventhandler == null) { throw new ArgumentNullException("itemchangedeventhandler"); } return(itemchangedeventhandler.BeginInvoke(sender, e, callback, null)); }
void ItemPropertyChanged(object sender, PropertyChangedEventArgs e) { ItemChangedEventHandler handler = ItemChanged; handler?.Invoke(sender, e); if (CollectionResetIfItemChanged) { OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset)); } }
public DataGrid() { base.SetStyle(ControlStyles.UserPaint, true); base.SetStyle(ControlStyles.Opaque, false); base.SetStyle(ControlStyles.SupportsTransparentBackColor, false); base.SetStyle(ControlStyles.UserMouse, true); this.gridState = new BitVector32(0x42827); this.dataGridTables = new GridTableStylesCollection(this); this.layout = this.CreateInitialLayoutState(); this.parentRows = new DataGridParentRows(this); this.horizScrollBar.Top = base.ClientRectangle.Height - this.horizScrollBar.Height; this.horizScrollBar.Left = 0; this.horizScrollBar.Visible = false; this.horizScrollBar.Scroll += new ScrollEventHandler(this.GridHScrolled); base.Controls.Add(this.horizScrollBar); this.vertScrollBar.Top = 0; this.vertScrollBar.Left = base.ClientRectangle.Width - this.vertScrollBar.Width; this.vertScrollBar.Visible = false; this.vertScrollBar.Scroll += new ScrollEventHandler(this.GridVScrolled); base.Controls.Add(this.vertScrollBar); this.BackColor = DefaultBackBrush.Color; this.ForeColor = DefaultForeBrush.Color; this.borderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.currentChangedHandler = new EventHandler(this.DataSource_RowChanged); this.positionChangedHandler = new EventHandler(this.DataSource_PositionChanged); this.itemChangedHandler = new ItemChangedEventHandler(this.DataSource_ItemChanged); this.metaDataChangedHandler = new EventHandler(this.DataSource_MetaDataChanged); this.dataGridTableStylesCollectionChanged = new CollectionChangeEventHandler(this.TableStylesCollectionChanged); this.dataGridTables.CollectionChanged += this.dataGridTableStylesCollectionChanged; this.SetDataGridTable(this.defaultTableStyle, true); this.backButtonHandler = new EventHandler(this.OnBackButtonClicked); this.downButtonHandler = new EventHandler(this.OnShowParentDetailsButtonClicked); this.caption = new DataGridCaption(this); this.caption.BackwardClicked += this.backButtonHandler; this.caption.DownClicked += this.downButtonHandler; this.RecalculateFonts(); base.Size = new Size(130, 80); base.Invalidate(); base.PerformLayout(); }