formato

11/04/2005 - 16:51 por Racsus | Informe spam
Hola

tengo un textbox con un "binding" enlace a datos. el caso
es que quiero transformarlo con la sentencia
format "#,##0" para que los números:

1000, 2000

los escriba como

1.000 2.000

Pero al ser un enlace a datos no me deja. Porque?

Saludos, Oscar
 

Leer las respuestas

#1 Eduardo A. Morcillo [MS MVP VB]
11/04/2005 - 18:06 | Informe spam
Utiliza los eventos Format y Parse del binding para formatear el campo y
"desformatearlo" para guardarlo en la BD. Ejemplo:

Private Sub Form_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AddHandler TextBox1.DataBindings("Text").Format, AddressOf
FormatInteger
AddHandler TextBox1.DataBindings("Text").Parse, AddressOf
ParseInteger

' Otra inicializacion aqui

End Sub

Private Sub FormatInteger(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs)

If e.DesiredType Is GetType(String) Then
e.Value = DirectCast(e.Value, Integer).ToString("#,##0")
End If

End Sub

Private Sub ParseInteger(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs)

If e.DesiredType Is GetType(Integer) AndAlso _
TypeOf e.Value Is String Then

e.Value = Integer.Parse(DirectCast(e.Value, String),
Globalization.NumberStyles.Number)

End If

End Sub

Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
https://mvp.support.microsoft.com/p...4EF5A4191C

Preguntas similares