VB.NET - How To Remove DataGridView Selected Row In VB.NET
In This VB.NET Tutorial We Will See How To Delete a DataGridView Selected Row In VB.NET Programming Language.
Project Source Code:
Imports System.Data.DataTable
Public Class Delete_DataGridView_Selected_Row
' Create a new datatable
Dim table As New DataTable("Table")
Private Sub Delete_DataGridView_Selected_Row_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Add columns to your datatable,
' with the name of the columns and their type
table.Columns.Add("Id", Type.GetType("System.Int32"))
table.Columns.Add("First Name", Type.GetType("System.String"))
table.Columns.Add("Last Name", Type.GetType("System.String"))
table.Columns.Add("Age", Type.GetType("System.Int32"))
' Add rows to the datatable with some data
table.Rows.Add(1, "XXXX", "YYYYY", 21)
table.Rows.Add(2, "SSDD", "hGSQ", 33)
table.Rows.Add(3, "fgfgd", "jgfdd", 53)
table.Rows.Add(4, "cvfghyghj", "sdrgtyh", 19)
table.Rows.Add(5, "hghfd", "ghjgdf", 36)
table.Rows.Add(6, "cvvdfgh", "juyrfdvc", 63)
table.Rows.Add(7, "aefht", "cvfhytrff", 21)
table.Rows.Add(8, "wghyuj", "mihgdwrh", 33)
table.Rows.Add(9, "qsztii", "bvdhjh", 53)
table.Rows.Add(10, "rytyufd", "esdfzr", 19)
'set data from datatable to datagridview
DataGridView1.DataSource = table
End Sub
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
' get the index of the selected row
Dim index As Integer
index = DataGridView1.CurrentCell.RowIndex
' delete the selected row
DataGridView1.Rows.RemoveAt(index)
End Sub
End Class
///////////////OUTPUT:
Before Deleting |
After Deleting |
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :