ListChanged
ListChangedEventHandler ListChanged;
Fires when the information in a DataView
changes,
including when DataRowView
objects are added,
deleted, modified, or moved. This event provides a
ListChangedEventArgs
object with information about
the type of change, and the old and new index of the item, if
appropriate. This event is rarely used in application programming (in
which case the DataTable
events are much more
useful) but is typically reserved for creating custom data bound
controls.
ListChangedEventArgs e
Exposes three properties. ListChangedType
provides
an enumerated value that indicates how the list changed.
NewIndex
and OldIndex
indicate
where an item moved, if the event is in response to a single row
change. For example, if an item is moved from position 0 to position
1, NewIndex
is 1, and OldIndex
is 0. If an item is deleted, NewIndex
contains the
former index of the deleted item, and OldIndex
isn’t used.
Table 28-2 lists the valid values for the
ListChangedType
enumeration.
Here’s an example that handles the
ListChanged
event and displays some information to
a debug window:
private void OnListChanged(object sender, ListChangedEventArgs args) { Debug.WriteLine("ListChanged:"); Debug.WriteLine("\t Type = " + args.ListChangedType); Debug.WriteLine("\tOldIndex = " + args.OldIndex); Debug.WriteLine("\tNewIndex = " + args.NewIndex); }