根据你的标题,你想把文本框的值插入到datatable中,然后使用
datagridview来显示它。
如果你想这样做,请参考下面的代码示例。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataTable table = new DataTable();
private void button1_Click(object sender, EventArgs e)
{
table.Rows.Add(txtName.Text, txtAge.Text, txtID.Text, txtScore.Text);
dataGridView1.DataSource = table;
}
private void Form1_Load(object sender, EventArgs e)
{
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Age", typeof(string));
table.Columns.Add("Id", typeof(string));
table.Columns.Add("Score", typeof(string));
}
}
如果上面的代码不能解决你的问题,你可以提供具体的异常和一段完成的代码。