Assembly : System.Windows.Forms (dans system.windows.forms.dll)
SyntaxePublic Event Parse As ConvertEventHandler
Dim instance As Binding Dim handler As ConvertEventHandler AddHandler instance.Parse, handler
public event ConvertEventHandler Parse
public: event ConvertEventHandler^ Parse { void add (ConvertEventHandler^ value); void remove (ConvertEventHandler^ value); }
/** @event */ public void add_Parse (ConvertEventHandler value) /** @event */ public void remove_Parse (ConvertEventHandler value)
JScript prend en charge l'utilisation d'événements mais pas la déclaration de nouveaux événements.
NotesLes événements Format et Parse vous permettent de créer des formats personnalisés pour afficher des données. Par exemple, si les données figurant dans une table sont de type Decimal, vous pouvez afficher les données dans un format monétaire local en affectant à la propriété Value du ConvertEventArgs la valeur mise en forme dans l'événement Format. Par conséquent, vous devez annuler la mise en forme de la valeur affichée dans l'événement Parse.
L'événement Parse se produit dans les conditions suivantes :
-
Lorsque la méthode EndCurrentEdit de BindingManagerBase est appelée.
-
Lorsque le Current du BindingManagerBase est modifié (en d'autres termes, lorsque Position est modifié).
Pour plus d'informations sur la gestion des événements, consultez Consommation d'événements.
ExempleL'exemple de code suivant crée un Binding, ajoute un délégué ConvertEventHandler aux événements Parse et Format et ajoute Binding au BindingsCollection d'un contrôle TextBox à l'aide de la propriété DataBindings. Le délégué d'événement DecimalToCurrencyString ajouté à l'événement Format, formate la valeur liée (de type Decimal) en tant que devise à l'aide de la méthode ToString. Le délégué d'événement CurrencyStringToDecimal ajouté à l'événement Parse, reconvertit la valeur affichée par le contrôle en type Decimal.
Private Sub DecimalToCurrencyString(sender As Object, cevent As ConvertEventArgs) ' The method converts only to string type. Test this using the DesiredType. If Not cevent.DesiredType Is 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 Not cevent.DesiredType Is 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
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: 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.get_DesiredType().Equals(String.class.ToType())) { return; } // Use the ToString method to format the value as currency ("c"). cevent.set_Value(((System.Decimal)(cevent.get_Value())).ToString("c")); } //DecimalToCurrencyString private void CurrencyStringToDecimal(Object sender, ConvertEventArgs cevent) { // The method converts back to decimal type only. if (!cevent.get_DesiredType().Equals(System.Decimal.class.ToType())) { return; } // Converts the string back to decimal using the static Parse method. cevent.set_Value(Decimal.Parse(cevent.get_Value().ToString(), NumberStyles.Currency, null)); } //CurrencyStringToDecimal 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.add_Format(new ConvertEventHandler(DecimalToCurrencyString)); b.add_Parse(new ConvertEventHandler(CurrencyStringToDecimal)); text1.get_DataBindings().Add(b); } //BindControl
private function DecimalToCurrencyString(sender, cevent : ConvertEventArgs) { // The method converts only to string type. Test this using the DesiredType. if(cevent.DesiredType != String.GetType()) return; cevent.Value = (Decimal(cevent.Value)).ToString("c"); } private function CurrencyStringToDecimal(sender, cevent : ConvertEventArgs) { // The method converts back to decimal type only. if(cevent.DesiredType != Decimal.GetType()) return; // Converts the string back to decimal using the static Parse method. cevent.Value = Decimal.Parse(cevent.Value.ToString(), NumberStyles.Currency, null); } private function BindControl() { // Creates the binding first. The OrderAmount is a Decimal type. var b : Binding = new Binding ("Text", ds, "Suppliers.CompanyName"); // Add the delegates to the event. b.add_Format(DecimalToCurrencyString); b.add_Parse(CurrencyStringToDecimal); text1.DataBindings.Add(b); }
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Informations de version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ