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
2 comments
commentssi le textbox n'est pas un texte s'il est un datetimerpicker comment on doit ecrire le code form.TextBox4.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString()
Replyau lieu de textbox4.text on doit ecrire datetimepicker.??? continuer le code de cette phrase s'il vous plait
J'ai un commentaire général. Le site ignore traiter les applications avec base de données access. C'est intéressant que cela soit également mis a la disposition des internautes
Reply