DataGridView.CellParsing 이벤트

정의

셀 값이 수정된 경우 셀의 편집 모드를 떠나면 발생합니다.

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

이벤트 유형

예제

다음 코드 예제에서는 이벤트를 처리 하는 방법을 보여 옵니다 CellParsing . 또한 클래스를 사용하는 DataGridViewCellParsingEventArgs 방법도 보여줍니다.

// Handling CellParsing allows one to accept user input, then map it to a different
// internal representation.
void dataGridView1_CellParsing( Object^ /*sender*/, DataGridViewCellParsingEventArgs^ e )
{
   if ( this->dataGridView1->Columns[ e->ColumnIndex ]->Name->Equals( "Release Date" ) )
   {
      if ( e != nullptr )
      {
         if ( e->Value != nullptr )
         {
            try
            {
               // Map what the user typed into UTC.
               e->Value = DateTime::Parse( e->Value->ToString() ).ToUniversalTime();

               // Set the ParsingApplied property to 
               // Show the event is handled.
               e->ParsingApplied = true;
            }
            catch ( FormatException^ /*ex*/ ) 
            {
               // Set to false in case another CellParsing handler
               // wants to try to parse this DataGridViewCellParsingEventArgs instance.
               e->ParsingApplied = false;
            }
         }
      }
   }
}
// Handling CellParsing allows one to accept user input, then map it to a different
// internal representation.
private void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
{
    if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Release Date")
    {
        if (e != null)
        {
            if (e.Value != null)
            {
                try
                {
                    // Map what the user typed into UTC.
                    e.Value = DateTime.Parse(e.Value.ToString()).ToUniversalTime();
                    // Set the ParsingApplied property to 
                    // Show the event is handled.
                    e.ParsingApplied = true;
                }
                catch (FormatException)
                {
                    // Set to false in case another CellParsing handler
                    // wants to try to parse this DataGridViewCellParsingEventArgs instance.
                    e.ParsingApplied = false;
                }
            }
        }
    }
}
' Handling CellParsing allows one to accept user input, then map it to a different
' internal representation.
Private Sub dataGridView1_CellParsing(ByVal sender As Object, _
    ByVal e As DataGridViewCellParsingEventArgs) _
    Handles dataGridView1.CellParsing

    If Me.dataGridView1.Columns(e.ColumnIndex).Name = _
        "Release Date" Then
        If e IsNot Nothing Then
            If e.Value IsNot Nothing Then
                Try
                    ' Map what the user typed into UTC.
                    e.Value = _
                    DateTime.Parse(e.Value.ToString()).ToUniversalTime()
                    ' Set the ParsingApplied property to 
                    ' Show the event is handled.
                    e.ParsingApplied = True

                Catch ex As FormatException
                    ' Set to false in case another CellParsing handler
                    ' wants to try to parse this DataGridViewCellParsingEventArgs instance.
                    e.ParsingApplied = False
                End Try
            End If
        End If
    End If
End Sub

설명

기본적으로 컨트롤은 DataGridView 셀에 표시된 사용자 지정 값을 셀 속성에 지정된 형식의 실제 기본 셀 ValueType 값으로 변환하려고 시도합니다. 이 변환에서는 셀 속성에서 반환 InheritedStyle 된 셀 스타일의 서식 속성을 사용합니다.

표준 변환이 요구 사항을 충족하지 않는 경우 이벤트를 처리 CellParsing 하여 필요한 형식으로 사용자 지정 값 변환을 제공합니다.

사용자는 속성에 지정된 메서드를 사용하여 편집 모드로 EditMode 전환할 수 있으며 편집 모드를 벗어나 다른 셀로 이동하거나 Enter 키를 눌러 변경 내용을 셀에 커밋할 수 있습니다. ESC를 누르면 커밋 CellParsing 되기 전에 값에 대한 변경 내용이 되돌리기 이벤트가 발생하지 않습니다. 이벤트는 CellParsing 최종 값이 원래 값과 동일한 경우에도 셀 값이 실제로 수정된 경우에만 발생합니다. 메서드를 호출할 CommitEdit 때도 발생합니다.

처리 하는 경우는 CellParsing 이벤트 값을 직접 변환할 수 있습니다 또는 기본 변환을 사용자 지정할 수 있습니다. 예를 들어, 변환할 수 있습니다 값 셀을 사용 하 여 직접 ParseFormattedValue 원하는 형식 변환기를 사용 하 여 메서드. 또는 기본 형식 변환기 값을 구문 분석 하지만 수정할 수는 NullValue, DataSourceNullValue, 및 FormatProvider 반환 하는 개체의 속성을 DataGridViewCellParsingEventArgs.InheritedCellStyle 셀을 사용 하 여 초기화 된 속성을 InheritedStyle 속성입니다.

초기의 서식이 지정 된 값을 바꿀 값으로 직접 변환 합니다 ConvertEventArgs.Value 속성 셀에 지정 된 형식에서 변환 된 값을 사용 하 여 ValueType 속성입니다. 더 이상 구문 분석 필요한 상태임을 나타내기 위해 설정 된 DataGridViewCellParsingEventArgs.ParsingApplied 속성을 true입니다.

완료 될 때 이벤트 처리기는 경우는 ConvertEventArgs.Valuenull 이거나 올바른 형식 또는 DataGridViewCellParsingEventArgs.ParsingApplied 속성은 falseValue 있는 셀을 사용 하는 구문 분석 되 ParseFormattedValue 기본 형식 변환기를 사용 하 여 메서드. 이 메서드의 기본 구현을 사용 하 여 값을 구문 분석 합니다 NullValue, DataSourceNullValue, 및 FormatProvider 셀 스타일의 속성에 전달 합니다. 값 같음 없으면 NullValue, 값을 사용 하 여 구문 분석 되는 FormatProvider 속성 및 형식 변환기에 전달 합니다.

셀 값을 표시 하기 위해 형식이 지정 된 값으로 변환 사용자 지정 처리는 CellFormatting 이벤트입니다.

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

적용 대상

추가 정보