BindingSource.AllowNew 속성

정의

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

속성 값

AddNew()를 사용하여 목록에 항목을 추가할 수 있으면 true이고, 그렇지 않으면 false입니다.

예외

List 속성이 나타내는 기본 목록이 고정 크기이거나 읽기 전용인데 이 속성이 true로 설정된 경우

기본 목록 형식에 매개 변수가 없는 생성자가 없을 때 이 속성이 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 속성입니다.

  • 항목의 형식에 매개 변수가 없는 생성자가 없습니다.

참고

이 속성의 값으로 설정 되 면 getter는 더 이상 기본 목록에 대 한 호출을 나타냅니다. 대신 단순히 값을 반환 될 때까지 이전에 설정 된는 ResetAllowNew 메서드가 호출 됩니다.

이 속성이 발생 하는 설정 합니다 ListChanged 이벤트를 ListChangedEventArgs.ListChangedType 로 설정 ListChangedType.Reset합니다.

속성을 trueAllowNew 설정하고 기본 목록 형식에 매개 변수가 없는 생성자가 없는 경우 이벤트를 처리 AddingNew 하고 적절한 형식을 만들어야 합니다.

적용 대상

추가 정보