CollectionChangeEventArgs 類別

定義

提供 CollectionChanged 事件的資料。Provides data for the CollectionChanged event.

public ref class CollectionChangeEventArgs : EventArgs
public class CollectionChangeEventArgs : EventArgs
type CollectionChangeEventArgs = class
    inherit EventArgs
Public Class CollectionChangeEventArgs
Inherits EventArgs
繼承
CollectionChangeEventArgs

範例

下列程式碼範例示範如何使用這個類型。The following code example demonstrates the use of this type. 在此範例中, 事件處理常式會報告AutoCompleteStringCollection.CollectionChanged事件的發生次數。In the example, an event handler reports on the occurrence of the AutoCompleteStringCollection.CollectionChanged 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.

若要執行範例程式碼, 請將它貼入包含名為AutoCompleteStringCollection AutoCompleteStringCollection1之類型實例的專案中。To run the example code, paste it into a project that contains an instance of type AutoCompleteStringCollection named AutoCompleteStringCollection1. 然後確定事件處理常式與AutoCompleteStringCollection.CollectionChanged事件相關聯。Then ensure that the event handler is associated with the AutoCompleteStringCollection.CollectionChanged event.

private void AutoCompleteStringCollection1_CollectionChanged(Object sender, CollectionChangeEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Action", e.Action );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Element", e.Element );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "CollectionChanged Event" );
}
Private Sub AutoCompleteStringCollection1_CollectionChanged(sender as Object, e as CollectionChangeEventArgs) _ 
     Handles AutoCompleteStringCollection1.CollectionChanged

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Action", e.Action)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Element", e.Element)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"CollectionChanged Event")

End Sub

備註

當您變更集合中的專案時 (例如, 藉由將元素新增至集合, 或從集合中移除元素), 會引發事件。CollectionChangedA CollectionChanged event is raised when you change which items are in a collection, for example, by adding an element to a collection or removing an element from the collection. 當個別元素變更其值時, 不會引發此事件。This event is not raised when an individual element changes its value.

建構函式

CollectionChangeEventArgs(CollectionChangeAction, Object)

初始化 CollectionChangeEventArgs 類別的新執行個體。Initializes a new instance of the CollectionChangeEventArgs class.

屬性

Action

取得指定集合變更方式的動作。Gets an action that specifies how the collection changed.

Element

取得變更的集合執行個體。Gets the instance of the collection with the change.

方法

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()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱