我还有一个问题。我已经绑定了datagridview,当我双击其中的行时,所有单元格值都被“转换”为文本框。我想做的是当我更改文本框值时,也必须在 datagridview 和 datatable 中进行更改。到目前为止,我只能更改 datagridview 的第一行,而不是选定的。这是我的代码:
private void buttonUredi_Click(object sender, EventArgs e)
{
int i = 0;
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
for (int j = 0; j < dataGridView1.ColumnCount; ++j)
{
competitorDataSet.Growns.Rows[i][j] = row.Cells[j].Value;
}
}
competitorDataSet.Growns.Rows[i][0] = textStN.Text;
competitorDataSet.Growns.Rows[i][1] = textN.Text;
competitorDataSet.Growns.Rows[i][2] = textSN.Text;
competitorDataSet.Growns.Rows[i][3] = textC.Text;
competitorDataSet.Growns.Rows[i][4] = textYB.Text;
this.grownsBindingSource.EndEdit();
if (dataGridView1.BindingContext[competitorDataSet.Growns] != null)
{
dataGridView1.BindingContext[competitorDataSet.Growns].EndCurrentEdit();
}
this.competitorDataSet.Growns.AcceptChanges();
}