Insert value in datagridview in c# visual studio.Using textbox, datagridview & button.
In this program, you will see how you can Insert values from textbox and show them into datagridview.
Step-Add 3 textbox,1 button,& datagridview from the toolbox and copy the following code.
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
DataTable Table = new DataTable();
DataRow dr;
private void Form1_Load(object sender, EventArgs e)
{
Table.Columns.Add("Name");
Table.Columns.Add("Address");
Table.Columns.Add("Age");
}
private void button1_Click(object sender, EventArgs e)
{
dr = Table.NewRow();
dr["Name"] = textBox1.Text;
dr["Address"] = textBox2.Text;
dr["Age"] = textBox3.Text;
Table.Rows.Add(dr);
dataGridView1.DataSource = Table;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
Step-Add 3 textbox,1 button,& datagridview from the toolbox and copy the following code.
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
DataTable Table = new DataTable();
DataRow dr;
private void Form1_Load(object sender, EventArgs e)
{
Table.Columns.Add("Name");
Table.Columns.Add("Address");
Table.Columns.Add("Age");
}
private void button1_Click(object sender, EventArgs e)
{
dr = Table.NewRow();
dr["Name"] = textBox1.Text;
dr["Address"] = textBox2.Text;
dr["Age"] = textBox3.Text;
Table.Rows.Add(dr);
dataGridView1.DataSource = Table;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
Comments
Post a Comment