Binding.Parse 이벤트
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
데이터 바인딩된 컨트롤의 값이 변경되면 발생합니다.
public:
event System::Windows::Forms::ConvertEventHandler ^ Parse;
public event System.Windows.Forms.ConvertEventHandler Parse;
public event System.Windows.Forms.ConvertEventHandler? Parse;
member this.Parse : System.Windows.Forms.ConvertEventHandler
Public Custom Event Parse As ConvertEventHandler
이벤트 유형
예제
다음 코드 예제에서는 만들고Binding, 대리자를 ConvertEventHandler 이벤트와 Format 이벤트에 추가하고Parse, 속성을 통해 DataBindings 컨트롤에 TextBox 추가 BindingBindingsCollection 합니다. 이벤트에 추가된 Format 이벤트 대리자는 DecimalToCurrencyString 메서드를 사용하여 ToString 바인딩된 값(Decimal형식)의 형식을 통화로 지정합니다.
CurrencyStringToDecimal 이벤트에 추가 Parse 된 이벤트 대리자는 컨트롤이 표시하는 값을 다시 형식으로 Decimal 변환합니다.
private:
void DecimalToCurrencyString( Object^ /*sender*/, ConvertEventArgs^ cevent )
{
// The method converts only to string type. Test this using the DesiredType.
if ( cevent->DesiredType != String::typeid )
{
return;
}
// Use the ToString method to format the value as currency ("c").
cevent->Value = ( (Decimal)(cevent->Value) ).ToString( "c" );
}
void CurrencyStringToDecimal( Object^ /*sender*/, ConvertEventArgs^ cevent )
{
// The method converts back to decimal type only.
if ( cevent->DesiredType != Decimal::typeid )
{
return;
}
// Converts the string back to decimal using the static Parse method.
cevent->Value = Decimal::Parse( cevent->Value->ToString(),
NumberStyles::Currency, nullptr );
}
void BindControl()
{
// Creates the binding first. The OrderAmount is typed as Decimal.
Binding^ b = gcnew Binding(
"Text", ds, "customers.custToOrders.OrderAmount" );
// Add the delegates to the event.
b->Format += gcnew ConvertEventHandler( this, &Form1::DecimalToCurrencyString );
b->Parse += gcnew ConvertEventHandler( this, &Form1::CurrencyStringToDecimal );
text1->DataBindings->Add( b );
}
private void DecimalToCurrencyString(object sender, ConvertEventArgs cevent)
{
// The method converts only to string type. Test this using the DesiredType.
if(cevent.DesiredType != typeof(string)) return;
// Use the ToString method to format the value as currency ("c").
cevent.Value = ((decimal) cevent.Value).ToString("c");
}
private void CurrencyStringToDecimal(object sender, ConvertEventArgs cevent)
{
// The method converts back to decimal type only.
if(cevent.DesiredType != typeof(decimal)) return;
// Converts the string back to decimal using the static Parse method.
cevent.Value = Decimal.Parse(cevent.Value.ToString(),
NumberStyles.Currency, null);
}
private void BindControl()
{
// Creates the binding first. The OrderAmount is typed as Decimal.
Binding b = new Binding
("Text", ds, "customers.custToOrders.OrderAmount");
// Add the delegates to the event.
b.Format += new ConvertEventHandler(DecimalToCurrencyString);
b.Parse += new ConvertEventHandler(CurrencyStringToDecimal);
text1.DataBindings.Add(b);
}
Private Sub DecimalToCurrencyString(sender As Object, cevent As ConvertEventArgs)
' The method converts only to string type. Test this using the DesiredType.
If cevent.DesiredType IsNot GetType(String) Then
Exit Sub
End If
' Use the ToString method to format the value as currency ("c").
cevent.Value = CType(cevent.Value, decimal).ToString("c")
End Sub
Private Sub CurrencyStringToDecimal(sender As Object, cevent As ConvertEventArgs)
' The method converts back to decimal type only.
If cevent.DesiredType IsNot GetType(Decimal) Then
Exit Sub
End If
' Convert the string back to decimal using the shared Parse method.
cevent.Value = Decimal.Parse(cevent.Value.ToString, _
NumberStyles.Currency, nothing)
End Sub
Private Sub BindControl
' Create the binding first. The OrderAmount is typed as Decimal.
Dim b As Binding = New Binding _
("Text", ds, "Customers.custToOrders.OrderAmount")
' Add the delegates to the event.
AddHandler b.Format, AddressOf DecimalToCurrencyString
AddHandler b.Parse, AddressOf CurrencyStringToDecimal
text1.DataBindings.Add(b)
End Sub
설명
Format 및 Parse 이벤트를 사용하면 데이터를 표시하기 위한 사용자 지정 형식을 만들 수 있습니다. 예를 들어 테이블의 데이터가 형식Decimal인 경우 이벤트의 형식이 지정된 값 Format 으로 속성을 ConvertEventArgs 설정 Value 하여 로컬 통화 형식으로 데이터를 표시할 수 있습니다. 따라서 이벤트에 표시된 값 Parse 의 서식을 해제해야 합니다.
이 Parse 이벤트는 다음과 같은 조건에서 발생합니다.
메서드가 EndCurrentEdit 호출되는 경우 BindingManagerBase 입니다.
변경되는 CurrentBindingManagerBase 경우(즉, 변경 시 Position ).
이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생시키기를 참조하십시오.