VB.NET - Get Selected Row Values From DataGridView To InputBox In VB.NET

vb.net datagridview selected row

VB.NET - How To Show Selected Row Values From DataGridView To InputBox Using VB.NET

                                                                                                                         

In This VB.NET Tutorial We Will See How To Displaying The Selected DataGridView Row Values In InpuBox Using VB.NET Programming Language.


Project Source Code:

Public Class VB_DataGridView_Row_Data_InputBox

    Dim table As New DataTable("Table")
    Private Sub VB_DataGridView_Row_Data_InputBox_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ' populate the datagridview using datatable
        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"))

        table.Rows.Add(1, "HJK", "KJH", 34)
        table.Rows.Add(2, "ERT", "IYT", 86)
        table.Rows.Add(3, "CVBN", "NBVC", 22)
        table.Rows.Add(4, "SDFGH", "HGFDS", 12)
        table.Rows.Add(5, "AZERTY", "YTREZA", 52)
        table.Rows.Add(6, "POIU", "UIOP", 31)
        table.Rows.Add(7, "AZSDFVB", "VCRTYUXA", 45)

        DataGridView1.DataSource = table

    End Sub

    Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick

        ' get selected DataGridView row index
        Dim selectedRowIndex As Integer

        selectedRowIndex = e.RowIndex

        Dim row As New DataGridViewRow()

        row = DataGridView1.Rows(selectedRowIndex)

        ' get the data from the row
        Dim id As String
        id = row.Cells(0).Value.ToString()

        Dim fn As String
        fn = row.Cells(1).Value.ToString()

        Dim ln As String
        ln = row.Cells(2).Value.ToString()

        Dim age As String
        age = row.Cells(3).Value.ToString()

        ' display row data in inputboxes
        InputBox("The Id", "Show Data", id)
        InputBox("The First Name", "Show Data", fn)
        InputBox("The Last Name", "Show Data", ln)
        InputBox("The Age", "Show Data", age)


    End Sub
End Class

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

vb.net show datagridview row data in inputox
show datagridview row data in inputox



Share this

Related Posts

Previous
Next Post »