CurrencyManager.ItemChanged 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生於目前項目變更時。
public:
event System::Windows::Forms::ItemChangedEventHandler ^ ItemChanged;
public event System.Windows.Forms.ItemChangedEventHandler ItemChanged;
public event System.Windows.Forms.ItemChangedEventHandler? ItemChanged;
member this.ItemChanged : System.Windows.Forms.ItemChangedEventHandler
Public Custom Event ItemChanged As ItemChangedEventHandler
事件類型
範例
下列程式碼範例會新增 和 PositionChanged 事件的事件處理常式 ItemChanged 。
void BindControl( DataTable^ myTable )
{
// Bind A TextBox control to a DataTable column in a DataSet.
textBox1->DataBindings->Add( "Text", myTable, "CompanyName" );
// Specify the CurrencyManager for the DataTable.
myCurrencyManager = dynamic_cast<CurrencyManager^>(this->BindingContext[myTable, ""]);
// Add event handlers.
myCurrencyManager->ItemChanged += gcnew ItemChangedEventHandler( this, &Form1::CurrencyManager_ItemChanged );
myCurrencyManager->PositionChanged += gcnew EventHandler( this, &Form1::CurrencyManager_PositionChanged );
// Set the initial Position of the control.
myCurrencyManager->Position = 0;
}
void CurrencyManager_PositionChanged( Object^ sender, System::EventArgs^ /*e*/ )
{
CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(sender);
Console::WriteLine( "Position Changed {0}", myCurrencyManager->Position );
}
void CurrencyManager_ItemChanged( Object^ sender, System::Windows::Forms::ItemChangedEventArgs^ /*e*/ )
{
CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(sender);
Console::WriteLine( "Item Changed {0}", myCurrencyManager->Position );
}
private void BindControl(DataTable myTable)
{
// Bind A TextBox control to a DataTable column in a DataSet.
textBox1.DataBindings.Add("Text", myTable, "CompanyName");
// Specify the CurrencyManager for the DataTable.
myCurrencyManager = (CurrencyManager)this.BindingContext[myTable, ""];
// Add event handlers.
myCurrencyManager.ItemChanged+=
new ItemChangedEventHandler(CurrencyManager_ItemChanged);
myCurrencyManager.PositionChanged+=
new EventHandler(CurrencyManager_PositionChanged);
// Set the initial Position of the control.
myCurrencyManager.Position = 0;
}
private void CurrencyManager_PositionChanged(object sender, System.EventArgs e){
CurrencyManager myCurrencyManager = (CurrencyManager) sender;
Console.WriteLine("Position Changed " + myCurrencyManager.Position);
}
private void CurrencyManager_ItemChanged(object sender, System.Windows.Forms.ItemChangedEventArgs e){
CurrencyManager myCurrencyManager = (CurrencyManager) sender;
Console.WriteLine("Item Changed " + myCurrencyManager.Position);
}
Private Sub BindControl(myTable As DataTable)
' Bind A TextBox control to a DataTable column in a DataSet.
textBox1.DataBindings.Add("Text", myTable, "CompanyName")
' Specify the CurrencyManager for the DataTable.
myCurrencyManager = CType(Me.BindingContext(myTable, ""), CurrencyManager)
' Add event handlers.
AddHandler myCurrencyManager.ItemChanged, AddressOf CurrencyManager_ItemChanged
AddHandler myCurrencyManager.PositionChanged, AddressOf CurrencyManager_PositionChanged
' Set the initial Position of the control.
myCurrencyManager.Position = 0
End Sub
Private Sub CurrencyManager_PositionChanged(sender As Object, e As System.EventArgs)
Dim myCurrencyManager As CurrencyManager = CType(sender, CurrencyManager)
Console.WriteLine(("Position Changed " & myCurrencyManager.Position))
End Sub
Private Sub CurrencyManager_ItemChanged(sender As Object, e As System.Windows.Forms.ItemChangedEventArgs)
Dim myCurrencyManager As CurrencyManager = CType(sender, CurrencyManager)
Console.WriteLine(("Item Changed " & myCurrencyManager.Position))
End Sub
備註
當使用者 ItemChanged 呼叫 ResumeBinding 或 SuspendBinding 方法時,就會發生此事件。
只有在 ItemChanged 專案本身以某種方式變更時,才會發生此事件。 例如,如果專案的值從 10 變更為 42,就會發生此事件。 這不應該與 PositionChanged 專案已變更為新專案的事件混淆。
如果基礎資料變更,也會發生此事件。 例如,如果您變更 的值 DataRowView ,就會 ItemChanged 發生 事件。
注意
如果您要建立使用 的控制項 CurrencyManager ,您應該使用 IBindingList.ListChanged 而不是 CurrencyManager.ItemChanged 事件。 的 ListChangedTypeListChangedEventArgs 屬性可讓您判斷已發生的動作類型。
如需處理事件的詳細資訊,請參閱 處理和引發事件。