Holas de nuevo, tengo un lio desde hace mucho, y no he podido solucionarlo.
tengo un DataGridView, en el cual ingreso un codigo en la primera celda le doy enter y me busca el producto que corresponde y su precio, todo lo hace bien,
el problema esta cuando abro otro formulario desde la primera celda con la tecla (f4) lo hace bien busco un producto segun descripcion, y me encuentra su codigo lo capturo y vuelvo al DgView a la primera celda con el codigo capturado le doy enter y no me ejecuta nada, necesariamente debo volver a digitar o escribir todo el codigo capturado para darle enter y siga funcionando, ademas el cierre del formulario donde busco es muy lento, me podrian ayudar???
este es el codigo que tengo:
Este codigo es del Datagridview
Código:
Private Sub Grilla_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Grilla.CellEndEdit
Select Case e.ColumnIndex
Case 0
cod = Grilla.Rows(Grilla.CurrentRow.Index).Cells(0).Value
MyCom.CommandText = "Select * From t_productos where idpro = " & "'" & cod & "'" & " and estado = 'Activo'"
MyCom.Connection = Conn
MyCom.CommandType = CommandType.Text
MyData.SelectCommand = MyCom
MyData.Fill(MyDs)
If MyDs.Tables(0).Rows.Count > 0 Then
Rs = MyDs.Tables(0).Rows(0)
Grilla.Rows(Grilla.CurrentRow.Index).Cells(1).Value = Rs("nombre")
Grilla.Rows(Grilla.CurrentRow.Index).Cells(2).Value = Rs("precio")
Grilla.Rows(Grilla.CurrentRow.Index).Cells(7).Value = Rs("unidad")
unid = Rs("unidad")
prec = Rs("precio")
Equi = Rs("equiva")
MyDs.Clear()
MyDs.Dispose()
MyData.Dispose()
SendKeys.Send("{UP}")
SendKeys.Send("{TAB}")
SendKeys.Send("{TAB}")
SendKeys.Send("{TAB}")
Else
MsgBox("El articulo No Existe o esta Inactivo", MsgBoxStyle.Critical)
SendKeys.Send("{UP}")
End If
Case 3
If IsDate(Grilla.Rows(Grilla.CurrentRow.Index).Cells(3).Value) Then
SendKeys.Send("{UP}")
SendKeys.Send("{TAB}")
Else
SendKeys.Send("{UP}")
End If
Fec = Grilla.Rows(Grilla.CurrentRow.Index).Cells(3).Value
Case 4
util = CDbl(Grilla.Rows(Grilla.CurrentRow.Index).Cells(4).Value)
cost = prec / (1.0 + (util / 100.0))
Grilla.Rows(Grilla.CurrentRow.Index).Cells(5).Value = cost
SendKeys.Send("{UP}")
SendKeys.Send("{TAB}")
SendKeys.Send("{TAB}")
Case 5
cost = Grilla.Rows(Grilla.CurrentRow.Index).Cells(5).Value
util = ((prec - cost) / cost) * 100.0
Grilla.Rows(Grilla.CurrentRow.Index).Cells(4).Value = Format(util, "#.00")
SendKeys.Send("{UP}")
SendKeys.Send("{TAB}")
Case 6
If IsNumeric(Grilla.Rows(Grilla.CurrentRow.Index).Cells(6).Value) Then
If Equi = 2 Then
MyCom.CommandText = "select * from t_equivale where idpro = " & "'" & cod & "'"
MyCom.Connection = Conn
MyCom.CommandType = CommandType.Text
MyData.SelectCommand = MyCom
MyData.Fill(MyDs)
FEquivale.bt1.Text = MyDs.Tables(0).Rows(0).Item("uni1").ToString
FEquivale.bt2.Text = MyDs.Tables(0).Rows(0).Item("uni2").ToString
FEquivale.bt3.Text = MyDs.Tables(0).Rows(0).Item("uni3").ToString
NomFormu = Me.Name
FEquivale.ShowDialog()
End If
sal = Grilla.Rows(Grilla.CurrentRow.Index).Cells(6).Value
cost = Grilla.Rows(Grilla.CurrentRow.Index).Cells(5).Value
subt = cost * (sal + depo)
Grilla.Rows(Grilla.CurrentRow.Index).Cells(8).Value = subt
SendKeys.Send("{UP}")
SendKeys.Send("{TAB}")
SendKeys.Send("{TAB}")
SendKeys.Send("{TAB}")
Else
SendKeys.Send("{UP}")
End If
End Select
MyDs.Clear()
MyDs.Dispose()
End Sub
y Este otro para buscar en otro formulario
Código:
Private Sub Grilla_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Grilla.KeyDown
If e.KeyCode = Keys.F4 Then
NomFormu = Me.Name
FBuscaArt.ShowDialog()
Grilla.Rows(Grilla.CurrentRow.Index).Cells(0).Value = VarIdPro
cod = VarIdPro
prec = VarPrePro
Grilla.Focus()
Grilla.Rows(Grilla.CurrentRow.Index).Cells(0).Selected = True
End If
End Sub
Espero su ayuda