两个TEXTBOX,一个DATAGRIDVIEW。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication59 { public partial class Form1 : Form { DataTable dt; int rowIndex = 0; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { dt = new DataTable(); dt.Columns.Add(" "); dt.Columns.Add("A"); dt.Columns.Add("B"); this.dataGridView1.DataSource = dt; } private void button1_Click(object sender, EventArgs e) { rowIndex++; DataRow dr = dt.NewRow(); dr[0] = rowIndex; dr[1] = this.textBox1.Text; dr[2] = this.textBox2.Text; dt.Rows.Add(dr); } } }
这只是单纯的模拟实现。实际上很多时候要用到数据库(数据库的操作可以参考其他我的博文,比如连接ACCESS,SQL SERVER)。有时候也需要点击DGV的任意一行实现增删改查,请学会了操作数据库后参看我的博文《点击DATAGRIDVIEW里的任意单元格实现增删改查》。