Affichage des articles dont le libellé est Show Selected Row Data In Another Form. Afficher tous les articles
Affichage des articles dont le libellé est Show Selected Row Data In Another Form. Afficher tous les articles

VB.NET DataGridView Show Selected Row Data In Another Form

VB.NET - How To Display DataGridView Selected Row Values On Another Form Using Visual Basic.NET


In This VB.NET Tutorial We Will See How To Get And Show DataGridView Selected Row Data To Another Form On GridView Click Using Visual Basic .NET Programming Language .


Project Source Code:

Public Class Form1

    Dim table As New DataTable("Table")

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        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)

        ' now set the datagridview datasource equals to your datatable name
        DataGridView1.DataSource = table

    End Sub

    

    Private Sub DataGridView1_Click(sender As Object, e As EventArgs) Handles DataGridView1.Click

        Dim form As New Form2

        form.TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString()
        form.TextBox2.Text = DataGridView1.CurrentRow.Cells(1).Value.ToString()
        form.TextBox3.Text = DataGridView1.CurrentRow.Cells(2).Value.ToString()
        form.TextBox4.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString()

        form.ShowDialog()

    End Sub
End Class


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

vb.net show datagridview data in another form