This is a migrated thread and some comments may be shown as answers.

Update to Grid on close of form

2 Answers 172 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 21 Oct 2016, 06:24 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 24 Oct 2016, 01:14 PM
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.
0
Laura
Top achievements
Rank 1
answered on 24 Oct 2016, 01:54 PM
Thank you Hristo, this worked perfectly!
Tags
GridView
Asked by
Laura
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Laura
Top achievements
Rank 1
Share this question
or