private void bindingList_ListChanged(object sender, ListChangedEventArgs e) { switch (e.ListChangedType) { // Well, usually fine-grained... The whole list has changed // utterly, so reload it. case ListChangedType.Reset: LoadItemsFromSource(); break; // A single item has changed, so just rebuild that. case ListChangedType.ItemChanged: object changedRow = m_currencyManager.List[e.NewIndex]; BeginUpdate(); BaseItems[e.NewIndex] = BuildItemForRow(changedRow); EndUpdate(); break; // A new item has appeared, so add that. case ListChangedType.ItemAdded: object newRow = m_currencyManager.List[e.NewIndex]; // We get this event twice if certain grid controls // are used to add a new row to a datatable: once when // the editing of a new row begins, and once again when // that editing commits. (If the user cancels the creation // of the new row, we never see the second creation.) // We detect this by seeing if this is a view on a // row in a DataTable, and if it is, testing to see if // it's a new row under creation. DataRowView drv = newRow as DataRowView; if (drv == null || !drv.IsNew) { // Either we're not dealing with a view on a data // table, or this is the commit notification. Either // way, this is the final notification, so we want // to add the new row now! BeginUpdate(); //BaseItems.Insert(e.NewIndex, BuildItemForRow(newRow)); BuildItemForRow(newRow); EndUpdate(); } break; // An item has gone away. case ListChangedType.ItemDeleted: if (e.NewIndex < BaseItems.Count) { BaseItems.RemoveAt(e.NewIndex); } break; // An item has changed its index. case ListChangedType.ItemMoved: BeginUpdate(); object moving = BaseItems[e.OldIndex]; BaseItems.Insert(e.NewIndex, moving); EndUpdate(); break; // Something has changed in the metadata. (This control is // too lazy to deal with this in a fine-grained fashion, // mostly because the author has never seen this event // occur... So we deal with it the simple way: reload // everything.) case ListChangedType.PropertyDescriptorAdded: case ListChangedType.PropertyDescriptorChanged: case ListChangedType.PropertyDescriptorDeleted: //LoadColumnsFromSource(); LoadItemsFromSource(); break; } }
public void RemoveAt(int index) { BaseItems.RemoveAt(index); }