CREANDO:
Dim dtTabla As New DataTable
Dim dcCodigo As New DataColumn("CODIGO", Type.GetType("System.Int32"))
Dim dcDescripcion As New DataColumn("DESCRIPCION", Type.GetType("System.String"))
dtTabla.Columns.AddRange(New DataColumn() {dcCodigo, dcDescripcion})
dtTabla.PrimaryKey = New DataColumn() {dcCodigo} 'Asignamos una clave primaria
AGREGANDO DATOS:
Try
Dim dr As DataRow
dr = dtTabla.NewRow
dr(0) = Convert.ToInt32(me.txtCodigo.text)
dr(1) = me.txtDescripcion.text
dtTabla.Rows.Add(dr)
Catch ex As ConstraintException
MsgBox("Ese Codigo ya existe.", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
End Try
End If
dgvDatos.DataSource = dtTabla
QUITANDO DATOS:
Try
dtTabla.Rows.Item(dgvDatos.CurrentRow.Index).Delete()
dgvDatos.DataSource = dtTabla
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
End Try
Prueba con ese codigo, Salu2