【发布时间】:2012-07-25 00:40:04
【问题描述】:
我有一个从数据库中获取数据并显示给用户的 datagridview,我还有三个文本框,如果我在 datgrid 中选择一个已经存在的行,然后通过文本输入值,用户可以通过这些文本框将值输入到 datagrid 视图中框进行更改,当我按下更改按钮时,在 db 和 datagridview 中都成功进行了更改 但是如果我在 datagrid 视图中选择一个空行并尝试输入值,我无法将新行添加到 datagrid 视图中,尽管允许用户添加新行设置为 true。
private void txtName_TextChanged(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 1)
{
dataGridView1.SelectedRows[0].Cells["Name"].Value = txtName.Text;
}
}
private void txtRelation_TextChanged(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 1)
{
dataGridView1.SelectedRows[0].Cells["Relation"].Value = txtRelation.Text;
}
}
private void txtID_TextChanged(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 1)
{
dataGridView1.SelectedRows[0].Cells["ID"].Value = txtID.Text;
}
}
【问题讨论】:
-
你的 DataGridView 是如何绑定的?
-
@DavidB 抱歉,我对此完全陌生,我正在对现有代码进行修改,这是什么意思?我的 DataGridView 从现有数据库中获取数据
-
@DavidB 它绑定到数据表
标签: c#