This documentation is archived and is not being maintained.

Working with DataView Events

You can use the ListChanged event of the DataView to determine if a view has been updated due to the addition, deletion, or modification of a row in the underlying table, due to the schema of the underlying table being modified by the addition or deletion of a column, or due to a change in a parent or child relationship. The ListChanged event will also notify you if the list of rows you are viewing has changed significantly due to the application of a new sort order or a filter.

The ListChanged event implements the ListChangedEventHandler delegate of the System.ComponentModel namespace and takes as input a ListChangedEventArgs object. You can determine what type of change has occurred using the ListChangedType enumeration value in the ListChangedType property of the ListChangedEventArgs object. For changes that involve adding, deleting, or moving rows, the new index of the added or moved row and the previous index of the deleted row can be accessed using the NewIndex property of the ListChangedEventArgs object. In the case of a moved row, the previous index of the moved row can be accessed using the OldIndex property of the ListChangedEventArgs object.

The DataViewManager also exposes a ListChanged event to notify you if a table has been added or removed, or if a change has been made to the Relations collection of the underlying DataSet.

The following code example shows how to add a ListChanged event handler.

  AddHandler custView.ListChanged, New System.ComponentModel.ListChangedEventHandler(AddressOf OnListChanged)

Private Shared Sub OnListChanged(sender As Object, args As System.ComponentModel.ListChangedEventArgs)
  Console.WriteLine("ListChanged:")
  Console.WriteLine(vbTab & "    Type = " & System.Enum.GetName(args.ListChangedType.GetType(), args.ListChangedType))
  Console.WriteLine(vbTab & "OldIndex = " & args.OldIndex)
  Console.WriteLine(vbTab & "NewIndex = " & args.NewIndex)
End Sub
[C#]
  custView.ListChanged  += new System.ComponentModel.ListChangedEventHandler(OnListChanged);

protected static void OnListChanged(object sender, System.ComponentModel.ListChangedEventArgs args)
{
  Console.WriteLine("ListChanged:");
  Console.WriteLine("\t    Type = " + args.ListChangedType);
  Console.WriteLine("\tOldIndex = " + args.OldIndex);
  Console.WriteLine("\tNewIndex = " + args.NewIndex);
}

See Also

Creating and Using DataViews | DataView Class | ListChangedEventHandler Delegate

Show: