How to Add a New Row To Datagridview From Another Form Using C#
In This C# Tutorial We Will See How To Insert A New Row To a Datagridview With Data From TextBoxes In Another Form Using C# Windows Form and Visual Studio Editor .
WATCH THIS C# TUTORIAL
Project Source Code:
// ------ First Create a Form Where You Put The Datagridview
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 Csharp_Tutorials.rst
{
public partial class FRM_GRIDVIEW : Form
{
public FRM_GRIDVIEW()
{
InitializeComponent();
}
// button to open the form where the textboxes are in
private void button_NewForm_Click(object sender, EventArgs e)
{
FormINFO finfo = new FormINFO(this);
finfo.Show();
}
}
}
// ------ Create a Form With TextBoxes
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 Csharp_Tutorials.rst
{
public partial class FormINFO : Form
{
FRM_GRIDVIEW fgrid;
public FormINFO(FRM_GRIDVIEW fg)
{
InitializeComponent();
this.fgrid = fg;
}
// button to add the row with the data to the datagridview
private void button_Add_Click(object sender, EventArgs e)
{
fgrid.dataGridView1.Rows.Add(textBox1.Text, textBox2.Text, textBox3.Text);
}
}
}
- Watch The Video Tutorial To See The Scond Method ( making the datagrdivew static )
OUTPUT:
Download Projects Source Code