![DatagridView (tablas) en Visual Basic.Net [08] 1 08](https://www.programadornovato.com/wp-content/uploads/2022/07/08-535x251.png)
DatagridView (tablas) en Visual Basic.Net [08]
En este tutorial manejaremos registros en una DatagridView (tablas) en Visual Basic.Net
- Insertamos un dataGridView tres textBox y dos botones.
- Al datagrid le colocamos tres columnas con Nombre, Apellido y Edad.
- A los textBox les colocamos los nombres txtNombre, txtApellido y txtEdad.
- Un botón será para agregar y el otro botón será para borrar registros.
Codigo de DatagridView (tablas) en Visual Basic.Net: https://github.com/programadornovato/FormularioVisualBasic/commit/9f8b0d822e6d2196f841f13e7efc0ccf5bf46344
Public Class Ventana2
Dim registroSel = 0
Private Sub Ventana2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lblDatos.Text = ""
End Sub
Private Sub btnAgregar_Click(sender As Object, e As EventArgs) Handles btnAgregar.Click
Dim n = dgPersonas.Rows.Add()
dgPersonas.Rows(n).Cells(0).Value = txtNombre.Text
dgPersonas.Rows(n).Cells(1).Value = txtApellido.Text
dgPersonas.Rows(n).Cells(2).Value = txtEdad.Text
txtNombre.Text = ""
txtApellido.Text = ""
txtEdad.Text = ""
End Sub
Private Sub dgPersonas_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgPersonas.CellClick
Dim n = dgPersonas.Rows.Count - 1
registroSel = e.RowIndex
If registroSel <> -1 And registroSel < n Then
Dim nombre = dgPersonas.Rows(registroSel).Cells(0).Value.ToString
Dim apellido = dgPersonas.Rows(registroSel).Cells(1).Value.ToString
Dim edad = dgPersonas.Rows(registroSel).Cells(2).Value.ToString
lblDatos.Text = nombre & " " & apellido & " " & edad
End If
End Sub
Private Sub btnBorrar_Click(sender As Object, e As EventArgs) Handles btnBorrar.Click
If registroSel <> -1 Then
dgPersonas.Rows.RemoveAt(registroSel)
lblDatos.Text = ""
End If
End Sub
End Class
[CURSO] VISUAL BASIC CON FORMULARIOS⛓️: https://www.youtube.com/playlist?list=PLCTD_CpMeEKT3ElKWfWYkyefyXdMxh-1v
[CURSO] Visual Basic.NET⛓️: https://www.youtube.com/watch?v=aiquJHzxNWw&list=PLCTD_CpMeEKSFwAFjvrfpvSwxmbs2maMo&ab_channel=programadornovato
[CURSO] C##️⃣: https://www.youtube.com/watch?v=NKPMGY6NCko&list=PLCTD_CpMeEKQSOU8Vf9VHXrZa2rc8X0X5&index=1&t=3s&ab_channel=programadornovatoprogramadornovato
[CURSO] C# CON FORMULARIOS#️⃣: https://www.youtube.com/watch?v=l0_U4oyOuns&list=PLCTD_CpMeEKTBih1VgeunCjc83ZQ6UBMI&index=1&ab_channel=programadornovatoprogramadornovato
[CURSO] C++ DE 0 A HEROE 🦸: https://www.youtube.com/watch?v=APN8aCyPvww&list=PLCTD_CpMeEKTofxs7iottRxJ5YPM7BOcc&ab_channel=programadornovato
[Curso] Java Netbeans GUI Completo☕: https://www.youtube.com/watch?v=18UA7X2ss8g&list=PLCTD_CpMeEKThfXo8D-RXOGu5FarO7_qv&ab_channel=programadornovato
🔗 Facebook: https://facebook.com/ProgramadorNovatoOficial
🔗 Twitter: https://twitter.com/programadornova
🔗 Linkedin: https://www.linkedin.com/in/programadornovato/
🔗 Instagram: https://www.instagram.com/programadornovato/
Ave que vuela, a la cazuela.