ListChangedEventArgs 类

定义

ListChanged 事件提供数据。Provides data for the ListChanged event.

public ref class ListChangedEventArgs : EventArgs
public class ListChangedEventArgs : EventArgs
type ListChangedEventArgs = class
    inherit EventArgs
Public Class ListChangedEventArgs
Inherits EventArgs
继承
ListChangedEventArgs

示例

下面的代码示例演示如何使用此类型。The following code example demonstrates the use of this type. 在此示例中, 事件处理程序报告BindingSource.ListChanged事件的发生。In the example, an event handler reports on the occurrence of the BindingSource.ListChanged event. 此报表可帮助你了解何时发生事件, 并可帮助你进行调试。This report helps you to learn when the event occurs and can assist you in debugging. 若要报告多个事件或频繁发生的事件, 请考虑MessageBox.ShowConsole.WriteLine消息替换为多行或将TextBox其追加到多行。To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

若要运行示例代码, 请将其粘贴到包含名为BindingSource BindingSource1的类型的实例的项目中。To run the example code, paste it into a project that contains an instance of type BindingSource named BindingSource1. 然后, 确保事件处理程序与BindingSource.ListChanged事件相关联。Then ensure that the event handler is associated with the BindingSource.ListChanged event.

private void BindingSource1_ListChanged(Object sender, ListChangedEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ListChangedType", e.ListChangedType );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "NewIndex", e.NewIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "OldIndex", e.OldIndex );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "PropertyDescriptor", e.PropertyDescriptor );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "ListChanged Event" );
}
Private Sub BindingSource1_ListChanged(sender as Object, e as ListChangedEventArgs) _ 
     Handles BindingSource1.ListChanged

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "ListChangedType", e.ListChangedType)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "NewIndex", e.NewIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "OldIndex", e.OldIndex)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "PropertyDescriptor", e.PropertyDescriptor)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"ListChanged Event")

End Sub

注解

更改中的数据时, 将引发事件。ListChanged IBindingListA ListChanged event is raised when the data in an IBindingList changes.

NewIndex属性指示已添加、更改或删除的项的索引。The NewIndex property indicates the index of the item that was added, changed, or deleted. 如果移动了某个项, 则NewIndex属性指示该项的新位置, OldIndex而属性指示旧位置。If an item was moved, the NewIndex property indicates the new location of the item and the OldIndex property indicates the old location.

如果更改只影响一个项, OldIndex则属性值为-1。If only one item is affected by a change, the OldIndex property value is -1.

构造函数

ListChangedEventArgs(ListChangedType, Int32)

如果给定更改类型和受影响项的索引,则初始化 ListChangedEventArgs 类的新实例。Initializes a new instance of the ListChangedEventArgs class given the type of change and the index of the affected item.

ListChangedEventArgs(ListChangedType, Int32, Int32)

如果给定更改类型以及被移动项的新索引和旧索引,则初始化 ListChangedEventArgs 类的新实例。Initializes a new instance of the ListChangedEventArgs class given the type of change and the old and new index of the item that was moved.

ListChangedEventArgs(ListChangedType, Int32, PropertyDescriptor)

如果给定更改类型、受影响项的索引以及描述受影响项的 ListChangedEventArgs,则初始化 PropertyDescriptor 类的新实例。Initializes a new instance of the ListChangedEventArgs class given the type of change, the index of the affected item, and a PropertyDescriptor describing the affected item.

ListChangedEventArgs(ListChangedType, PropertyDescriptor)

如果给定更改类型和受影响的 ListChangedEventArgs,则初始化 PropertyDescriptor 类的新实例。Initializes a new instance of the ListChangedEventArgs class given the type of change and the PropertyDescriptor affected.

属性

ListChangedType

获取更改类型。Gets the type of change.

NewIndex

获取受更改影响的项的索引。Gets the index of the item affected by the change.

OldIndex

获取已移动的项的旧索引。Gets the old index of an item that has been moved.

PropertyDescriptor

获取添加、更改或删除的 PropertyDescriptorGets the PropertyDescriptor that was added, changed, or deleted.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅