VB.NET - How To Delete A DataGridView Selected Row Using VB.NET

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

    End Sub

End Class


vb.net delete datagridview row
Before Deleting

vb.net remove datagridview selected row
After Deleting

Share this

Related Posts

Next Post »


3 juillet 2017 à 21:23 delete

After entering the invoice data as much as 10 lines then save. After that I call the data back to add some items that are entered.
How do I call back data that I have entered as many as 10 lines.

Thank you