Export (0) Print
Expand All

ConvertEventArgs.DesiredType Property

Gets the data type of the desired value.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public Type DesiredType { get; }

Property Value

Type: System.Type
The Type of the desired value.

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 != typeof(string)) return;

   cevent.Value = ((decimal) cevent.Value).ToString("c");
}

private void CurrencyStringToDecimal(object sender, ConvertEventArgs cevent)
{   
   // The method converts only to decimal type.
   if(cevent.DesiredType != typeof(decimal)) return;

   cevent.Value = Decimal.Parse(cevent.Value.ToString(),
   NumberStyles.Currency, null);
}



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft