This documentation is archived and is not being maintained.

DataView.ListChanged Event

Occurs when the list managed by the DataView changes.

[Visual Basic]
Public Overridable Event ListChanged As ListChangedEventHandler
[C#]
public virtual event ListChangedEventHandler ListChanged;
[C++]
public: virtual __event ListChangedEventHandler* ListChanged;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type ListChangedEventArgs containing data related to this event. The following ListChangedEventArgs properties provide information specific to this event.

Property Description
ListChangedType Gets the way that the list changed.
NewIndex Gets the new index of the item in the list.
OldIndex Gets the old index of the item in the list.

Example

[Visual Basic, C#, C++] The following example adds a handler for the the ListChanged event of a DataView.

[Visual Basic] 
Public Sub CreateDataView(dt As DataTable) 
  Dim dv As DataView = New DataView(dt, "", "ContactName", DataViewRowState.CurrentRows)

  AddHandler dv.ListChanged, New System.ComponentModel.ListChangedEventHandler(AddressOf OnListChanged)
End Sub

Protected Sub OnListChanged(sender as Object, args As System.ComponentModel.ListChangedEventArgs)
  Console.WriteLine("ListChanged:")
  Console.WriteLine(vbTab & "    Type = " & args.ListChangedType)
  Console.WriteLine(vbTab & "OldIndex = " & args.OldIndex)
  Console.WriteLine(vbTab & "NewIndex = " & args.NewIndex)
End Sub

[C#] 
public void CreateDataView(DataTable dt) 
{
  DataView dv = new DataView(dt, "", "ContactName", DataViewRowState.CurrentRows);

  dv.ListChanged  += new System.ComponentModel.ListChangedEventHandler(OnListChanged);
}

protected 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);
}

[C++] 
public:
    void CreateDataView(DataTable* dt)
    {
    DataView* dv = new DataView(dt, S"", S"ContactName", DataViewRowState::CurrentRows);
    dv->ListChanged += new System::ComponentModel::ListChangedEventHandler(this, &Sample::OnListChanged);
    };

protected:
    void OnListChanged(Object* sender, System::ComponentModel::ListChangedEventArgs* args)
    {
    Console::WriteLine(S"ListChanged:");
    Console::WriteLine(S"\t    Type = {0}", __box(args->ListChangedType));
    Console::WriteLine(S"\tOldIndex = {0}", __box(args->OldIndex));
    Console::WriteLine(S"\tNewIndex = {0}", __box(args->NewIndex));
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

DataView Class | DataView Members | System.Data Namespace

Show: