ListChangedEventArgs 类

定义

ListChanged 事件提供数据。

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

示例

下面的代码示例演示了此类型的用法。 在此示例中,事件处理程序报告事件的发生情况 BindingSource.ListChanged 。 此报表可帮助你了解事件发生的时间,并可以帮助你进行调试。 若要报告多个事件或频繁发生的事件,请考虑将 MessageBox.Show 替换为 Console.WriteLine 或将消息追加到多行 TextBox

若要运行示例代码,请将其粘贴到包含名为 BindingSource1的 类型的BindingSource实例的项目中。 然后,确保事件处理程序与 BindingSource.ListChanged 事件相关联。

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 中的数据发生更改时,将引发 事件 IBindingList

属性 NewIndex 指示已添加、更改或删除的项的索引。 如果移动了某个项, NewIndex 属性指示该项的新位置, OldIndex 属性指示旧位置。

如果只有一项受更改影响,则 OldIndex 属性值为 -1。

构造函数

ListChangedEventArgs(ListChangedType, Int32)

如果给定更改类型和受影响项的索引,则初始化 ListChangedEventArgs 类的新实例。

ListChangedEventArgs(ListChangedType, Int32, Int32)

如果给定更改类型以及被移动项的新索引和旧索引,则初始化 ListChangedEventArgs 类的新实例。

ListChangedEventArgs(ListChangedType, Int32, PropertyDescriptor)

如果给定更改类型、受影响项的索引以及描述受影响项的 ListChangedEventArgs,则初始化 PropertyDescriptor 类的新实例。

ListChangedEventArgs(ListChangedType, PropertyDescriptor)

如果给定更改类型和受影响的 ListChangedEventArgs,则初始化 PropertyDescriptor 类的新实例。

属性

ListChangedType

获取更改类型。

NewIndex

获取受更改影响的项的索引。

OldIndex

获取已移动的项的旧索引。

PropertyDescriptor

获取添加、更改或删除的 PropertyDescriptor

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅