Update to Grid on close of form

3 posts, 1 answers
  1. Laura
    Laura avatar
    3 posts
    Member since:
    May 2016

    Posted 21 Oct Link to this post

    Hi,

    If a user has changed a cell, and before they move to another row, they click on the Form's Close button, how can I force the update to that row/record?  Right now, on the FormClosing event, I am calling EndEdit() and that is committing the change to the cell, BUT, if I call the Update method to my table adapter right after that, the change is not committed to the database.

    I would prefer to NOT have to use a Save button.

    Thank you,

    Laura

  2. Answer
    Hristo
    Admin
    Hristo avatar
    714 posts

    Posted 24 Oct Link to this post

    Hello Laura,

    Thank you for writing.

    It appears that you have encountered a known issue in RadGridView logged here: FIX. RadGridView - the last row is not updated when the grid is bound to IEditableObject. The fix will be publicly available with our service pack release later this week. 

    Until then please call the EndEdit method of the IEditableObject instance. A suitable place is the handler of the CellValueChanged event handler: 
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
     
            this.radGridView1.CellValueChanged += radGridView1_CellValueChanged;
     
            this.FormClosing += Form1_FormClosing;
        }
     
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.categoriesTableAdapter.Update(this.nwindDataSet);
        }
     
        private void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            IEditableObject editbaleObject = e.Row.DataBoundItem as IEditableObject;
            if (editbaleObject != null)
            {
                editbaleObject.EndEdit();
            }
        }
     
        private void Form1_Load(object sender, EventArgs e)
        {
            this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);
        }
    }

    I am also sending you my test project. 

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Laura
    Laura avatar
    3 posts
    Member since:
    May 2016

    Posted 24 Oct in reply to Hristo Link to this post

    Thank you Hristo, this worked perfectly!
Back to Top