Minggu, 28 Februari 2016

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
        DataGridView1.Rows.RemoveAt(index)

    End Sub

End Class

///////////////OUTPUT:

vb.net delete datagridview row
Before Deleting

vb.net remove datagridview selected row
After Deleting

Bagikan

Jangan lewatkan

VB.NET - How To Delete A DataGridView Selected Row Using VB.NET
4/ 5
Oleh

Subscribe via email

Suka dengan artikel di atas? Tambahkan email Anda untuk berlangganan.