CLR: .Net / Mono / Boo / Otros CLR > VB .NET
Eliminar La última Fila de un DataGridView
(1/1)
DriverSoftVzla:
HOLA AMIGOS.
LES HECHO EL CUENTO:
TENGO UN DATAGRIDVIEW DESCONECTADO, LO QUE QUIERO ES ELIMINAR LA ULTIMA FILA CUANDO ESTA VACIA, PERO QUIERO QUE LO HAGA AUTOMATICAMENTE. ME EXPLICO, SI ESTOY EN LA ULTIMA FILA Y ME MUEVO A LA FILA ANTERIOR, QUIERO QUE LA ELIMINE AUTOMATICAMENTE.
SI LO HAGO MANUALMENTE FUNCIONA, EJEMPLO:
Case Keys.F4 'Elimina Una Fila del DatagridView
If (_DGV1.RowCount > 0) Then
Me._DGV1.Rows.Remove(Me._DGV1.CurrentRow)
End If
HE PROBADO ELIMINARLA EN LOS EVENTOS: RowValidating, RowValidated, RowLeave
EJEMPLO:
Private Sub _DGV1_RowValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles _DGV1.RowValidated
If (_DGV1.RowCount > 0) Then
If _DGV1.Rows(e.RowIndex).Cells(0).Value() = String.Empty Then
Me._DGV1.Rows.Remove(Me._DGV1.CurrentRow)
End If
End If
End Sub
Y ARROJA: "La operación no se puede realizar en este controlador de eventos"
NO SE DONDE HACERLO, GRACIAS POR TODA LA AYUDA PRESTADA.
fm89-10:
hola para empezar no escribas en mayusculas.Mira lo que puedes hacer es crear un evento de teclado que cuando presiones la flecha de arriba del teclado te elimine la fila.(si el cursor esta en la fila vacia y presionas flecha arriba te la elimine).
--- Código: vb.net --- Private Sub DataGridView1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyUp Dim v As Integer v = e.KeyValue If (v = 38) Then If (_DGV1.RowCount > 0) Then DataGridView1.AllowUserToAddRows = False End If End If End Sub
alguna duda me dices :hola:
DriverSoftVzla:
Hola, gracias por responder.
Permiteme escribir algo en mayuscula, MUCHAS GRACIAS
y ahora si, nada en mayus.
Tomando tu ejemplo se me prendio el bombillo, y lo hice asi, claro aun estoy averiguando como controlo cuando cambie de fila con el mouse, pero mientras tenemos este adelanto:
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData as
System.Windows.Forms.Keys) As Boolean
If (Not _DGV1.Focused) AndAlso _
(Not _DGV1.IsCurrentCellInEditMode) Then Return MyBase.ProcessCmdKey(msg, keyData)
Select Case keyData
Case Keys.Up, Keys.Down, Keys. 'Eliminar Fila Vacia
If Eliminar_Fila_Vacia() Then
Return True
End If
Case Keys.F8
If Me._DGV1.Rows(Me._DGV1.CurrentCell.RowIndex).Cells(0).Selected Then 'Cells(0) es la columna CODIGO
SeleccionarCodigo()
End If
End Select
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Private Function Eliminar_Fila_Vacia() As Boolean
Dim i As Integer = _DGV1.CurrentCell.RowIndex 'Indice Fila a Eliminar
If (_DGV1.RowCount > 0) Then
If _DGV1.Rows(i).Cells(0).Value() = String.Empty Then
_DGV1.Rows.Remove(Me._DGV1.CurrentRow) 'Elimina Fila
_DGV1.CurrentCell = _DGV1.Rows(i - 1).Cells(0) 'Selecciono Celda Anterior
Return True
End If
End If
Return False
End Function
Navegación
Ir a la versión completa