winformsdevexpressdevexpress-windows-uidevexpress-gridcontrol

How to update fields of a new record with data from a database?


I use:
  - MS SQL Server 2014 database;
  - Entity Framework.

I am using GridControl with an "empty row" element.
The user is trying to add a new entry in the GridControl.
After adding a new record does not update the field, which is formed by the database.
In my case, this field is "ID".
It can also be other fields that the database forms.
The "ID" field is updated only after the new record is being edited.

Question.
How to make the field that is filled with the database updated in the GridControl after adding a new entry in the GridControl?

namespace Rsh.frm.frm3.Core.ModelEFFrm_3
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class PrbEntitiesF3 : DbContext
    {
        public PrbEntitiesF3()
            : base("name=PrbEntitiesF3")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<tbl_930_3_2_Test> tbl_930_3_2_Test { get; set; }
    }
}

namespace Rsh.frm.frm3.Core.ModelEFFrm_3
{
    using System;
    using System.Collections.Generic;

    public partial class tbl_930_3_2_Test
    {
        public int Id { get; set; }
        public string Text { get; set; }
    }
}


public partial class Frm3UC : UserControl
{

PrbEntitiesF3 entiF3;

 public Frm3UC()
        {
            InitializeComponent();

            entiF3 = new PrbEntitiesF3();
        }


public void FillGrid3()
{           
    entiF3.tbl_930_3_2_Test.Load();
    bs3.DataSource = entiF3.tbl_930_3_2_Test.Local.ToBindingList();               
    gridControl3.DataSource = bs3;
}

public void Save()
{
    entiF3.SaveChanges();
}

}

enter image description here

Update_1
I want to make the logic work:
1. User filled the field.
enter image description here

  1. User. Clicked "Enter".
  2. The code (or standard tools "devexpress") adds a new entry to the Grid.
    enter image description here

  3. The code (or standard tools "devexpress") saves an entry to the database.

  4. The code (or standard tools "devexpress") fills in the fields that the database creates.
    In my case, this is the "ID" field.
    I want to say that the value of the "ID" field is created in the database.
    This value needs to be displayed in the Grid for the new record that the user added.

enter image description here


Solution

  • The solution is to handle the GridView_FocusedRowChanged event.

    Please see the following screencast:

    https://screencast-o-matic.com/watch/cqnZFt0Qeb