VB.NET - How To Insert A Row To DataGridView From TextBox Using VB.NET
In This VB.NET Tutorial We Will See How To Add a Row To DataGridView Using TextBoxes Using VB.NET Programming Language.
Project Source Code:
Imports System.Data.DataTable
Public Class Add_Row_To_DataGridView_Using_TextBoxes
' Create a new datatable
Dim table As New DataTable("Table")
Private Sub Add_Row_To_DataGridView_Using_TextBoxes_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"))
' now set the datagridview datasource equals to your datatable name
DataGridView1.DataSource = table
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
' Add rows to the datatable using textboxes
table.Rows.Add(TextBoxID.Text, TextBoxFN.Text, TextBoxLN.Text, TextBoxAGE.Text)
' now set the datagridview datasource again
DataGridView1.DataSource = table
End Sub
End Class
///////////////OUTPUT:
VB.NET - Adding Rows To DataGridView From TextBoxes
Download Projects Source Code
2 comments
commentsWorks well..! Thank you..!
ReplyDoes not work, the first value is replaced by a second value in stead make another new row
Reply