我正在将数据从datagridview保存到表格,但是有一个文本框可以在datagridview&中添加数据数据。我需要在表格中保存特定添加行的数据。但是它没有显示正确的结果。
private void btnadd_Click(object sender, EventArgs e)
{
String[] row = new String[7];
row[0] = cmbsfno.SelectedItem.ToString();
row[1] = cmbstandard.SelectedItem.ToString();
row[2] = cmbprority.SelectedItem.ToString();
row[3] = comboBox3.SelectedItem.ToString();
row[4] = cmbpartfamily.SelectedItem.ToString();
row[5] = comboBox2.SelectedItem.ToString();
row[6] = txtremark.Text;
dataGridView1.Rows.Add(row);
cnt++;
}
当用户在datagridview中添加一些记录时如何将其保存在表格中。保存但正确保存文本框数据
答案 0 :(得分:0)
private void btnadd_Click(object sender, EventArgs e)
{
String[] row = new String[7];
dataGridView1.Rows[cnt].Cell[0].value = cmbsfno.SelectedItem.ToString();
dataGridView1.Rows[cnt].Cell[1].value = cmbstandard.SelectedItem.ToString();
dataGridView1.Rows[cnt].Cell[2].value = cmbprority.SelectedItem.ToString();
dataGridView1.Rows[cnt].Cell[3].value = comboBox3.SelectedItem.ToString();
dataGridView1.Rows[cnt].Cell[4].value = cmbpartfamily.SelectedItem.ToString();
dataGridView1.Rows[cnt].Cell[5].value = comboBox2.SelectedItem.ToString();
dataGridView1.Rows[cnt].Cell[6].value = txtremark.Text;
dataGridView1.Rows.Add(row);
cnt++;
}