ConvertEventArgs::DesiredType Property
.NET Framework (current version)
Gets the data type of the desired value.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The DesiredType property enables you to check the type of the property that the value is being converted to.
The following code example uses the DesiredType property to determine whether the conversion of one type to another can proceed. The DecimalToCurrencyString method tests whether the DesiredType is a string. If not, the code exits the method. Similarly, the CurrencyStringToDecimal method tests whether the DesiredType is a Decimal, and exits if it is not true.
private: void DecimalToCurrencyString( Object^ /*sender*/, ConvertEventArgs^ cevent ) { // The method converts only to string type. if ( cevent->DesiredType != String::typeid ) { return; } cevent->Value = ( (Decimal^)(cevent->Value) )->ToString( "c" ); } void CurrencyStringToDecimal( Object^ /*sender*/, ConvertEventArgs^ cevent ) { // The method converts only to decimal type. if ( cevent->DesiredType != Decimal::typeid ) { return; } cevent->Value = Decimal::Parse( cevent->Value->ToString(), NumberStyles::Currency, nullptr ); }
.NET Framework
Available since 1.1
Available since 1.1
Show: