Hello,
check this link , it will be most helpful for creating such program.
DataGridView MSDN Library[
^]
If you still need help look at this simple windows form program in C#, that I have made. It consists of one Form with one DataGridView table with two buttons for adding new row with new cell values taken from text boxes ,and one button for deleting last row in the DataGridView.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Insert_value_from_TextBox__to__DataGridView
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
SetInitialValues();
}
void EnterValuesToDatagridView(object sender, EventArgs e)
{
int Row = 0;
if (textBox1.Text != "" & textBox2.Text != "" & textBox3.Text != "" & textBox4.Text != "")
{
dataGridView1.Rows.Add();
Row = dataGridView1.Rows.Count - 2;
dataGridView1[0,Row].Value = textBox1.Text;
dataGridView1[1,Row].Value = textBox2.Text;
dataGridView1[2,Row].Value = textBox3.Text;
dataGridView1[3,Row].Value = textBox4.Text;
dataGridView1.Refresh();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
else
{
MessageBox.Show("You did not entered values to all text boxes","Error",
MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
void DeleteLastRow(object sender, EventArgs e)
{
int LastRow = 0;
LastRow = dataGridView1.Rows.Count - 2;
if (LastRow > -1)
{
dataGridView1.Rows.RemoveAt(LastRow);
}
}
void SetInitialValues()
{
dataGridView1.ReadOnly = true;
dataGridView1.AllowUserToDeleteRows = true;
dataGridView1.RowCount = 1;
dataGridView1.Refresh();
textBox1.Text = "Hemant";
textBox2.Text = "IT";
textBox3.Text = "25";
textBox4.Text = "10 rupee";
}
}
}
All the best,
Perić Željko