BindingSource.AllowNew プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As BindingSource Dim value As Boolean value = instance.AllowNew instance.AllowNew = value
/** @property */ public boolean get_AllowNew () /** @property */ public void set_AllowNew (boolean value)
AddNew を使用してリストに項目を追加できる場合は true。それ以外の場合は false。


AllowNew プロパティの既定値は、基底のデータ ソースの型によって異なります。基底のリストに、IBindingList インターフェイスが実装されている場合、このプロパティは基底のリストで代行されます。それ以外の場合で、基底のリストが次の特性のうちいずれかを備えている場合、このプロパティは false を返します。
![]() |
---|
このプロパティの値を設定すると、取得側は、以降の呼び出しを基底のリストに参照しません。代わりに、ResetAllowNew メソッドが呼び出されるまで、以前に設定された値を返すだけです。 |
このプロパティを設定すると、ListChangedEventArgs.ListChangedType が ListChangedType.Reset に設定された ListChanged イベントが発生します。
AllowNew プロパティを true に設定するとき、基底のリストの型に既定のコンストラクタがない場合は、AddingNew イベントを処理して、適切な型を作成する必要があります。

次のコード例では、BindingSource コンポーネントの AllowNew プロパティを使用して、ユーザーが BindingSource コンポーネントの基底のリストに項目を追加できるようにする方法を示します。このプロパティを true に設定すると、バインドされた DataGridView コントロールに新しいレコード用の行が表示されます。
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
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; }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からBindingSource.AllowNew プロパティを検索する場合は、下記のリンクをクリックしてください。

- BindingSource.AllowNew プロパティのページへのリンク