相关疑难解决方法(0)

DataGridView AllowUserToAddRow 属性不起作用

我有一个使用实体框架的简单项目,我有一个DataGridViewForm并将其AllowUserToAddRow属性设置为true,但我仍然无法向其中添加新行。

这是我的代码:

DBEntities context = new DBEntities();
private void Form1_Load(object sender, EventArgs e)
{
    var q = (from i in context.myTable
             select i).ToList();
    DataGridView.DataSource = q;
}

private void btnSave_Click(object sender, EventArgs e)
{
    context.SaveChanges();
    MessageBox.Show("saved successfully");
}
Run Code Online (Sandbox Code Playgroud)

如果我使用BindingSource控件,它允许我插入行,DataGridView但是在context.SaveChanges()我在数据库文件中不调用任何插入之后,使用这种方法。所以我想也许与这个问题有关,DataGridView属性true AllowUserToAddRow不允许我在 中插入行DataGridView

c# linq entity-framework datagridview bindingsource

5
推荐指数
1
解决办法
6966
查看次数

标签 统计

bindingsource ×1

c# ×1

datagridview ×1

entity-framework ×1

linq ×1