DataGridViewCellParsingEventHandler 대리자

정의

CellParsingDataGridView 이벤트를 처리할 메서드를 나타냅니다.

public delegate void DataGridViewCellParsingEventHandler(System::Object ^ sender, DataGridViewCellParsingEventArgs ^ e);
public delegate void DataGridViewCellParsingEventHandler(object sender, DataGridViewCellParsingEventArgs e);
public delegate void DataGridViewCellParsingEventHandler(object? sender, DataGridViewCellParsingEventArgs e);
type DataGridViewCellParsingEventHandler = delegate of obj * DataGridViewCellParsingEventArgs -> unit
Public Delegate Sub DataGridViewCellParsingEventHandler(sender As Object, e As DataGridViewCellParsingEventArgs)

매개 변수

sender
Object

이벤트 소스입니다.

e
DataGridViewCellParsingEventArgs

이벤트 데이터를 포함하는 DataGridViewCellParsingEventArgs입니다.

예제

다음 코드 예제에서는 DataGridViewCellParsingEventHandler 날짜 항목의 유효성을 검사 합니다.

// 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

설명

처리를 CellParsing 셀에 의해 지정 된 형식의 값으로 사용자 지정 값 변환할 사용자 지정 값을 제공 하는 이벤트 ValueType 속성입니다.

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

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

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

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

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

DataGridViewCellParsingEventHandler 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보