Visual Basic.NET - funcion ProcessCmdKey

 
Vista:

funcion ProcessCmdKey

Publicado por RICHARD J. (16 intervenciones) el 01/06/2009 16:24:49
HOLA A TODOS LOS AMIGOS DE LA WEB.

SOLICITO LA YUDA DEBIDO A QUE QUIERO CONTROLAR LA ENTRADA DE DATOS A UNA COLUMNA DATAGRIDVIEW, ESTA COLUMNA SOLO DEBE ACEPTAR NUMEROS, COMA Y PUNTO.

PENSE EN UTILIZAR EL PROCESSCMDKEY PERO TENGO PROBLEMAS PARA VALIDAR EL KEYDATA.

DE ANTEMANO GRACIAS POR LA AYUDA PRESTADA.

SALUDOS.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

RE:funcion ProcessCmdKey

Publicado por P. J. (706 intervenciones) el 01/06/2009 22:12:27
Prueba con este procedimiento

Private Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
If e.ColumnIndex = 0 Then
If Not e.FormattedValue.ToString = String.Empty Then
If Not IsNumeric(e.FormattedValue.ToString) Then
If Not e.FormattedValue.ToString = "," Or Not e.FormattedValue.ToString = "." Then
'AQUI TAMBIEN PUEDES MOSTRAR UN MSGBOX, AUNQUE ME PARECE ALGO FASTIDIOSO, LO DEJO A TU CRITERIO
e.Cancel = True ' BLOQUEMOS PARA QUE NO SALGA DE LA CELDA
End If
End If
End If
End If
End Sub

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:GRACIAS P.J.

Publicado por solfinker (12 intervenciones) el 08/01/2011 18:23:48
Funciona estupendamente.

Gracias.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:funcion ProcessCmdKey

Publicado por Richard J. (16 intervenciones) el 08/01/2011 22:31:08
Encontre esta otra forma.
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
If (Not _DGV2.Focused) AndAlso (_DGV2.IsCurrentCellInEditMode) Then
If (_DGV2.CurrentCell.ColumnIndex = 0) Then
Select Case keyData
Case Keys.D0 To Keys.D9, Keys.NumPad0 To Keys.NumPad9, Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Down, Keys.Delete, Keys.Enter, Keys.Tab, Keys.Oemcomma
Return MyBase.ProcessCmdKey(msg, keyData)
Case Keys.Decimal, Keys.OemPeriod
SendKeys.Send("{BKSP}")
SendKeys.Send(Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator)
Return MyBase.ProcessCmdKey(msg, keyData)
Case Else
Return True
End Select
End If
End If
End Function


Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar