0

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

eusataf
  • 807
  • 1
  • 12
  • 24
  • Hi, just to clarify your question, do you want to save the data into the database as soon as you switch to the next record? – jjthebig1 Feb 12 '19 at 13:48
  • @jjthebig1 I updated the question. See "Update_1". Did I manage to answer your question? – eusataf Feb 12 '19 at 19:13
  • @jjthebig1 Excuse me. Do you have any suggestions how to solve my problem? – eusataf Feb 19 '19 at 17:41
  • Sorry for the delay. I was had a few deadlines and I couldn't respond. I just posted an answer and I hope this is what you were looking for. – jjthebig1 Feb 24 '19 at 18:29

1 Answers1

3

The solution is to handle the GridView_FocusedRowChanged event.

Please see the following screencast:

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

jjthebig1
  • 629
  • 7
  • 12
  • Thanks for the answer. Maybe you have the opportunity to help with this issue. See link - **[link](https://stackoverflow.com/questions/54855911/how-to-make-changes-to-the-query-saved-in-the-database)** – eusataf Feb 24 '19 at 20:24