BindingSource.AddingNew イベント
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As BindingSource Dim handler As AddingNewEventHandler AddHandler instance.AddingNew, handler
public: event AddingNewEventHandler^ AddingNew { void add (AddingNewEventHandler^ value); void remove (AddingNewEventHandler^ value); }


AddingNew イベントは、List プロパティで表される基底のリストに新しいオブジェクトが追加される前に発生します。このイベントは、AddNew メソッドが呼び出された後、新しい項目が作成されて基底のリストに追加される前に発生します。このイベントを処理することにより、BindingSource からクラスを派生せずに、項目を作成および挿入するためのカスタムの動作をプログラム上で定義できます。これは、イベント ハンドラで System.ComponentModel.AddingNewEventArgs パラメータの NewObject プロパティを新しい項目に設定することによって実行できます。AddingNew イベントで作成された新しいオブジェクトは、リストに格納されている型と同じ型であることが必要です。型が異なる場合、例外が発生します。DataView または DataTable にバインドされている場合は、新しい DataRowView をリストに追加できないため、NewObject プロパティを設定することはできません。
新しい項目のカスタムの機能を定義する方法の詳細については、AddNew メソッドのトピックを参照してください。イベント処理の詳細については、「イベントの利用」を参照してください。

BindingSource コンポーネントを使用して、リストを DataGridView コントロールにバインドするコード例を次に示します。新しい項目は、AddingNew のイベント ハンドラによってリストに追加されます。次のコード例は、「方法 : Windows フォーム BindingSource を使用した項目の追加をカスタマイズする」で示されている例の一部です。
Public Sub New() ' Set up the form. Me.Size = New Size(800, 800) AddHandler Me.Load, AddressOf Form1_Load Me.Controls.Add(status) ' Set up the DataGridView control. Me.customersDataGridView.Dock = DockStyle.Fill Me.Controls.Add(customersDataGridView) End Sub
public Form1() { // Set up the form. this.Size = new Size(800, 800); this.Load += new EventHandler(Form1_Load); this.Controls.Add(status); // Set up the DataGridView control. this.customersDataGridView.Dock = DockStyle.Fill; this.Controls.Add(customersDataGridView); // Attach an event handler for the AddingNew event. this.customersBindingSource.AddingNew += new AddingNewEventHandler(customersBindingSource_AddingNew); // Attach an event handler for the ListChanged event. this.customersBindingSource.ListChanged += new ListChangedEventHandler(customersBindingSource_ListChanged); }
public: MainForm() { customersBindingSource = gcnew BindingSource; customersDataGridView = gcnew DataGridView; status = gcnew StatusBar; // Set up the form. this->Size = System::Drawing::Size(600, 400); this->Text = "BindingSource.AddingNew sample"; this->Load += gcnew EventHandler(this, &MainForm::OnMainFormLoad); this->Controls->Add(status); // Set up the DataGridView control. this->customersDataGridView->Dock = DockStyle::Fill; this->Controls->Add(this->customersDataGridView); // Attach an event handler for the AddingNew event. this->customersBindingSource->AddingNew += gcnew AddingNewEventHandler(this, &MainForm::OnCustomersBindingSourceAddingNew); // Attach an event handler for the ListChanged event. this->customersBindingSource->ListChanged += gcnew ListChangedEventHandler(this, &MainForm::OnCustomersBindingSourceListChanged); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


BindingSource クラス
BindingSource メンバ
System.Windows.Forms 名前空間
AddNew
OnAddingNew
System.ComponentModel.AddingNewEventArgs
Weblioに収録されているすべての辞書からBindingSource.AddingNew イベントを検索する場合は、下記のリンクをクリックしてください。

- BindingSource.AddingNew イベントのページへのリンク