DataGridView.DefaultValuesNeeded 이벤트

정의

기본값으로 채워질 수 있도록 사용자가 새 레코드에 대한 행을 입력할 때 발생합니다.

public:
 event System::Windows::Forms::DataGridViewRowEventHandler ^ DefaultValuesNeeded;
public event System.Windows.Forms.DataGridViewRowEventHandler DefaultValuesNeeded;
public event System.Windows.Forms.DataGridViewRowEventHandler? DefaultValuesNeeded;
member this.DefaultValuesNeeded : System.Windows.Forms.DataGridViewRowEventHandler 
Public Custom Event DefaultValuesNeeded As DataGridViewRowEventHandler 

이벤트 유형

예제

다음 코드 예제에서는이 이벤트를 처리할 수 있는 방법을 보여 줍니다. 이 예제에서 지정된 열의 셀은 기본값으로 채워집니다. 열의 CustomerID 경우 고유한 고객 ID를 생성하는 별도의 메서드(구현되지 않음)에서 값이 검색됩니다.

이 예제를 실행하려면 열 이름을 실제 DataGridView 컨트롤의 열 개체 이름으로 바꾸고 적절한 기본값을 제공합니다. 이름으로 열을 지정할 때 열 머리글 텍스트가 아닌 열 개체의 이름을 사용해야 합니다.

private void dataGridView1_DefaultValuesNeeded(object sender,
    System.Windows.Forms.DataGridViewRowEventArgs e)
{
    e.Row.Cells["Region"].Value = "WA";
    e.Row.Cells["City"].Value = "Redmond";
    e.Row.Cells["PostalCode"].Value = "98052-6399";
    e.Row.Cells["Country"].Value = "USA";
    e.Row.Cells["CustomerID"].Value = NewCustomerId();
}
Private Sub dataGridView1_DefaultValuesNeeded(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) _
    Handles dataGridView1.DefaultValuesNeeded

    With e.Row
        .Cells("Region").Value = "WA"
        .Cells("City").Value = "Redmond"
        .Cells("PostalCode").Value = "98052-6399"
        .Cells("Country").Value = "USA"
        .Cells("CustomerID").Value = NewCustomerId()
    End With

End Sub

설명

이 이벤트를 사용하면 사용자가 행에 들어갈 때 새 레코드의 행을 채울 수 있습니다. 행의 초기 값은 각 열 CellTemplate 의 속성에서 반환된 DataGridViewCell 의 속성에서 DefaultNewRowValue 가져옵니다.

데이터 바인딩 모드에서는 데이터 바인딩 열의 모든 셀 값이 외부 데이터 원본에 저장됩니다. 사용자가 새 레코드의 행을 입력하면 이벤트가 발생하기 전에 데이터 원본에 새 행이 DefaultValuesNeeded 만들어집니다. 이벤트 처리기에서 속성을 채우는 DataGridViewRowEventArgs.Row 경우 값이 데이터 원본에 직접 추가됩니다.

가상 모드에서 이 이벤트가 발생한 후 새 행의 CellValuePushed 각 셀에 대해 이벤트가 발생하므로 사용자 지정 데이터 저장소에 기본값을 저장할 수 있습니다. 그런 다음 새 행의 CellValueNeeded 각 셀에 대해 이벤트가 발생하여 이벤트에 저장한 CellValuePushed 값을 검색한 후 표시됩니다.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

적용 대상

추가 정보