DataGridView AllowUserToAddRow property doesn't work

后端 未结 4 670
离开以前
离开以前 2020-12-06 14:52

I have a simple project with Entity Framework, I have a DataGridView in my Form and I set its AllowUserToAddRow property to true

4条回答
  •  不知归路
    2020-12-06 15:03

    I have just painfully upgraded to EF 6 from 4 and I have a similar issue, the solution in EF6 is below and I have shown a where statement for further help.

    DBEntities context = new DBEntities();
    private void Form1_Load(object sender, EventArgs e)
    {
      context.MyTable.Where(e => e.myField == 1).Load();
    
      BindingSource bs = new BindingSource();
      bs.DataSource = context.MyTable.Local.ToBindingList();
      myDatagridView.DataSource = bs;
    }
    

    You can now use context.SaveChanges(); to save the changes or inserts

提交回复
热议问题