VB2010 ¿Cómo asignar valor a una variable en lostfocus?

I want to assign a string value to a variable in the DataGridView LostFocus event. I found that I can't just do variable = "string value, it will give me the "Unable to cast object of type ‘system.eventargs’ to type ‘system.windows.forms.datagridviewcelleventargs’" error.

The function created by double-clicking on the datagridview is:

Private Sub DataGridViewInvoice_LostFocus(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewInvoice.LostFocus

Thanks, Raymond

preguntado el 09 de marzo de 12 a las 14:03

Where is the failing code? The event in which you try to assign a variabile has nothing to do with the assignment -

1 Respuestas

That's the wrong parameters for the .LostFocus event.

Dim s As String = ""
Sub DataGridView1_LostFocus(sender As Object, e As EventArgs) Handles DataGridView1.LostFocus
    s = "Hello"
End Sub

Also, maybe you should consider the .Leave event instead, as suggested in the remarks at http://msdn.microsoft.com/en-us/library/system.windows.forms.control.lostfocus%28v=vs.90%29.aspx

respondido 09 mar '12, 17:03

Hi Andrew,thanks for the link. I don't encounter any issue after using the Leave event. - Raymond

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.