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

Preguntas similare

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
Respuesta Responder a este mensaje
#2 Racsus
12/04/2005 - 08:51 | Informe spam
Da error al ejecutar la funcion FormatInteger. porque
puede ser?


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...73D2-BD48-


4197-A380-104EF5A4191C


.

Respuesta Responder a este mensaje
#3 Eduardo A. Morcillo [MS MVP VB]
12/04/2005 - 16:29 | Informe spam
¿Que error? Yo lo probe y funciona ok, aunque claro supuse que el tipo del
campo era entero. Si no lo es, el DirectCast es el que falla. En ese caso
convierte al tipo del campo en lugar de a Integer.

Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
https://mvp.support.microsoft.com/p...4EF5A4191C
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida