Согласно вашему заголовку, вы хотели бы вставить значение текстового поля в 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));
}
}
Результат: ![enter image description here](https://i.stack.imgur.com/Lv31b.gif)
Если приведенный выше код не может решить вашу проблему, вы можете указать исключение c и завершить код.