BindingSource.AllowNew プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
AddNew() メソッドを使用してリストに項目を追加できるかどうかを示す値を取得または設定します。
public:
virtual property bool AllowNew { bool get(); void set(bool value); };
public virtual bool AllowNew { get; set; }
member this.AllowNew : bool with get, set
Public Overridable Property AllowNew As Boolean
プロパティ値
true
AddNew()を使用してリストに項目を追加できる場合は。それ以外の場合はfalse。
例外
このプロパティは、true プロパティによって表される基になるリストが固定サイズであるか、読み取り専用である場合にListに設定されます。
このプロパティは true に設定され、基になるリスト型にパラメーターなしのコンストラクターがない場合、 AddingNew イベントは処理されません。
例
次のコード例では、AllowNew コンポーネントの BindingSource プロパティを使用して、ユーザーがBindingSource コンポーネントの基になるリストに新しい項目を追加できるようにする方法を示します。 このプロパティを true に設定すると、バインドされた DataGridView コントロールに新しいレコードの行が表示されます。
Form1()
{
// Set up the form.
this->Size = System::Drawing::Size( 800, 800 );
this->Load += gcnew EventHandler( this, &Form1::Form1_Load );
// Set up the RadioButton controls.
this->allRadioBtn->Text = L"All";
this->allRadioBtn->Checked = true;
this->allRadioBtn->CheckedChanged += gcnew EventHandler(
this, &Form1::allRadioBtn_CheckedChanged );
this->allRadioBtn->Dock = DockStyle::Top;
this->currentRadioBtn->Text = L"Current";
this->currentRadioBtn->CheckedChanged += gcnew EventHandler(
this, &Form1::currentRadioBtn_CheckedChanged );
this->currentRadioBtn->Dock = DockStyle::Top;
this->noneRadioBtn->Text = L"None";
this->noneRadioBtn->CheckedChanged += gcnew EventHandler(
this, &Form1::noneRadioBtn_CheckedChanged );
this->noneRadioBtn->Dock = DockStyle::Top;
this->buttonPanel->Controls->Add( this->allRadioBtn );
this->buttonPanel->Controls->Add( this->currentRadioBtn );
this->buttonPanel->Controls->Add( this->noneRadioBtn );
this->buttonPanel->Dock = DockStyle::Bottom;
this->Controls->Add( this->buttonPanel );
// Set up the DataGridView control.
this->customersDataGridView->AllowUserToAddRows = true;
this->customersDataGridView->Dock = DockStyle::Fill;
this->Controls->Add( customersDataGridView );
// Add the StatusBar control to the form.
this->Controls->Add( status );
// Allow the user to add new items.
this->customersBindingSource->AllowNew = true;
// Attach an event handler for the AddingNew event.
this->customersBindingSource->AddingNew +=
gcnew AddingNewEventHandler(
this, &Form1::customersBindingSource_AddingNew );
// Attach an eventhandler for the ListChanged event.
this->customersBindingSource->ListChanged +=
gcnew ListChangedEventHandler(
this, &Form1::customersBindingSource_ListChanged );
// Set the initial value of the ItemChangedEventMode property
// to report all ListChanged events.
this->customersBindingSource->ItemChangedEventMode =
ItemChangedEventMode::All;
// Attach the BindingSource to the DataGridView.
this->customersDataGridView->DataSource =
this->customersBindingSource;
}
public Form1()
{
// Set up the form.
this.Size = new Size(800, 800);
this.Load += new EventHandler(Form1_Load);
// Set up the DataGridView control.
this.customersDataGridView.AllowUserToAddRows = true;
this.customersDataGridView.Dock = DockStyle.Fill;
this.Controls.Add(customersDataGridView);
// Add the StatusBar control to the form.
this.Controls.Add(status);
// Allow the user to add new items.
this.customersBindingSource.AllowNew = true;
// Attach an event handler for the AddingNew event.
this.customersBindingSource.AddingNew +=
new AddingNewEventHandler(customersBindingSource_AddingNew);
// Attach an eventhandler for the ListChanged event.
this.customersBindingSource.ListChanged +=
new ListChangedEventHandler(customersBindingSource_ListChanged);
// Attach the BindingSource to the DataGridView.
this.customersDataGridView.DataSource =
this.customersBindingSource;
}
Public Sub New()
' Set up the form.
Me.Size = New Size(800, 800)
AddHandler Me.Load, AddressOf Form1_Load
' Set up the DataGridView control.
Me.customersDataGridView.AllowUserToAddRows = True
Me.customersDataGridView.Dock = DockStyle.Fill
Me.Controls.Add(customersDataGridView)
' Add the StatusBar control to the form.
Me.Controls.Add(status)
' Allow the user to add new items.
Me.customersBindingSource.AllowNew = True
' Attach the BindingSource to the DataGridView.
Me.customersDataGridView.DataSource = Me.customersBindingSource
End Sub
注釈
AllowNew プロパティの既定値は、基になるデータ ソースの種類によって異なります。 基になるリストに IBindingList インターフェイスが実装されている場合、このプロパティは基になるリストに委任されます。 それ以外の場合、基になるリストに次のいずれかの特性がある場合、このプロパティは false を返します。
IList.IsFixedSize プロパティによって決まる固定サイズです。
IList.IsReadOnly プロパティによって決定される読み取り専用です。
項目の型にパラメーターなしのコンストラクターがありません。
Note
このプロパティの値が設定されると、getter は基になるリストの呼び出しを参照しなくなります。 代わりに、 ResetAllowNew メソッドが呼び出されるまで以前に設定された値を返すだけです。
このプロパティを設定すると、ListChangedが ListChangedEventArgs.ListChangedType に設定されたListChangedType.Reset イベントが発生します。
AllowNew プロパティを true に設定し、基になるリスト型にパラメーターなしのコンストラクターがない場合は、AddingNew イベントを処理し、適切な型を作成する必要があります。