C# - How To Insert Data From Textboxes To DataGridView In C#
In This C# Code We Will See How To Add A Row To DataGridView From TextBoxes
In C# Programming Language.
Source Code:
In C# Programming Language.
Source Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Add_Row_To_DataGridView_Using_TextBoxes : Form { public Add_Row_To_DataGridView_Using_TextBoxes() { InitializeComponent(); } DataTable table = new DataTable(); private void Add_Row_To_DataGridView_Using_TextBoxes_Load(object sender, EventArgs e) { // set datatable columns values table.Columns.Add("Id", typeof(int));// data type int table.Columns.Add("First Name", typeof(string));// datatype string table.Columns.Add("Last Name", typeof(string));// datatype string table.Columns.Add("Age", typeof(int));// data type int dataGridView1.DataSource = table; } //add a row to datatable private void btnAdd_Click(object sender, EventArgs e) { table.Rows.Add(textBoxID.Text, textBoxFN.Text, textBoxLN.Text, textBoxAGE.Text); dataGridView1.DataSource = table; } } }
/////////////////////////////////OUTPUT:
Row Added |
Update A DataGridView Row With TextBox
Add Delete And Update DataGridView Row Using TextBoxes
Download Projects Source Code