Validar DataGridview
Publicado por Alexis (23 intervenciones) el 20/02/2009 21:09:21
Hola
tengo un data grid con un datasource y unos campos...
Quiero que el programa no guarde ningún dato si alguno de estos campos está en blanco. He intentado lo siguiente:
Private Sub ConfigpartidasDataGridView_CellValidating(
Select e.ColumnIndex
Case 2
If Me.ConfigpartidasDataGridView(e.ColumnIndex, e.RowIndex).IsInEditMode Then
If Me.ConfigpartidasDataGridView(e.ColumnIndex, e.RowIndex).Value Is DBNull.Value Then
If String.IsNullOrEmpty(Me.ConfigpartidasDataGridView(e.ColumnIndex, e.RowIndex).Value) Then
e.Cancel = True
End If
Else
If Not String.IsNullOrEmpty(e.FormattedValue.ToString()) Then
'EN CASO QUE QUE LA CELDA NO ESTE VACIA DEBO REALIZAR OTRO PROCESO
End If
End If
End Select
Esto me provoca el siguiente error al salir de una celda vacía
La conversión del tipo 'DBNull' en el tipo 'String' no es válida.
y debugando veo que el error lo dá en la línea:
If String.IsNullOrEmpty(Me.ConfigpartidasDataGridView(e.ColumnIndex, e.RowIndex).Value)
¿Alguna idea?
Es en otro método en el que lo he de hacer?
tengo un data grid con un datasource y unos campos...
Quiero que el programa no guarde ningún dato si alguno de estos campos está en blanco. He intentado lo siguiente:
Private Sub ConfigpartidasDataGridView_CellValidating(
Select e.ColumnIndex
Case 2
If Me.ConfigpartidasDataGridView(e.ColumnIndex, e.RowIndex).IsInEditMode Then
If Me.ConfigpartidasDataGridView(e.ColumnIndex, e.RowIndex).Value Is DBNull.Value Then
If String.IsNullOrEmpty(Me.ConfigpartidasDataGridView(e.ColumnIndex, e.RowIndex).Value) Then
e.Cancel = True
End If
Else
If Not String.IsNullOrEmpty(e.FormattedValue.ToString()) Then
'EN CASO QUE QUE LA CELDA NO ESTE VACIA DEBO REALIZAR OTRO PROCESO
End If
End If
End Select
Esto me provoca el siguiente error al salir de una celda vacía
La conversión del tipo 'DBNull' en el tipo 'String' no es válida.
y debugando veo que el error lo dá en la línea:
If String.IsNullOrEmpty(Me.ConfigpartidasDataGridView(e.ColumnIndex, e.RowIndex).Value)
¿Alguna idea?
Es en otro método en el que lo he de hacer?
Valora esta pregunta


0