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

Saving while editing

14 Answers 162 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Thomas
Top achievements
Rank 1
Thomas asked on 23 Dec 2011, 03:52 PM
Hello,

If I insert a new row in a RadGridView, then start editing it, then click outside of that row, then click on my save button.
The record go to the database.

If I insert a new row in a RadGridView, then start editing it, then immediately without click on my save button clicking outside of the row .
The records is not in the database.

this is how the code associated with my save button goes:
            this.myRadGridView.EndEdit();
            this.myBindingSource.EndEdit();
            this.myDataEntities.SaveChanges();

How could I correct this behaviour ?

Thank you for your help.

PS : I forgot to say I had the record through the BindingSource(this.myBindingSource.AddNew();)

14 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 26 Dec 2011, 02:12 PM
Hi Thomas,

 As I understand your query, you would like to save the changed once you have done editing the row (when you click outside of the row).

If this is the case, then you could save changes for your DataEntities when the RowEditEnded event  is fired.

Is this what do you need?

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Thomas
Top achievements
Rank 1
answered on 26 Dec 2011, 02:45 PM
I have no 'RowEditEnded' event on myDataEntities(ObjectContext).

But anyway, it's not what I want to do.

Let's say I have my grid, and a custom 'Save' button, and a custom 'Insert' button.
What I want:
1. The user insert a row in the BindingSource (myBindingSource.AddNew());
2. The row is added to the RadGridView.
3. The user start editing
4. The user writes some text
5. The user clicks directly on his 'Save' button, and not anywhere else on the grid or the form.
6. Somewhere after the clicks, I want the editing to end before I save the data to the database.
7. I save the data.

What is currently happning :
1 to 5: same as above
6. The data are saved.
7.The editing end --> which means that the new data are not in the DB, but they appear in the grid as if the were in the DB, until the next 'refresh'.

I thought that running methods myRadGridView.EndEdit(); and/or myBindingSource.EndEdit() somewhere between the click and the saving of the data would end the edit, but apparently, it doesn't, and the click happens before the end of the edition.
0
Dimitrina
Telerik team
answered on 27 Dec 2011, 03:48 PM
Hello,

The RowEditEnded is an event of the RadGridView and it is raised when a row edit ends. 

 Thank you for providing more details. I am reading through your description step by step, but still I cannot understand how after you move the focus to the Save button, the editing does not end. Is the Save button outside of the GridView? 

I do not understand those lines:

"REQUIRED: 6. Somewhere after the clicks, I want the editing to end before I save the data to the database.
WRONG:       6. The data are saved. "

"REQUIRED: 7. I save the data. "
WRONG:        7.The editing end --> which means that the new data are not in the DB, but they appear in the grid as if the were in the DB, until the next 'refresh'. " 

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Thomas
Top achievements
Rank 1
answered on 27 Dec 2011, 04:10 PM
I don't really know how to be more clear about steps 6&7 but it seems you almost got it, when I click on my save button, the edit ends, BUT it ends after the button's click event and not before.
I've have even tried to put 'this.Save_RadButton.Focus();' in the button's click method.

Yes the button is outside of the GridView.

(And I still don't see any 'RowEditEnded' event on my RadGridView, the only thing I see that look more or less like it is 'CellEndEdit', but anyway, what I would like to do is to force the editing to end, not cactch an event telling me that it has ended.)

0
Dimitrina
Telerik team
answered on 27 Dec 2011, 04:27 PM
Hi,

 Could you please tell me what version of the RadControls do you use?

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Thomas
Top achievements
Rank 1
answered on 27 Dec 2011, 05:25 PM
I was using 2011 Q3, I've just upgrade to 2011 Q3 SP1, which brings no change in this situation.
0
Dimitrina
Telerik team
answered on 28 Dec 2011, 09:04 AM
Hi,

The GridView has a RowEditEnded event, it would be strange if your GridView does not have it.
Have you set a value for the ActionOnLostFocus proeprty of the GridView? By default its value is "CommitEdit". How does your project behave if you set its value to "None"?

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Thomas
Top achievements
Rank 1
answered on 28 Dec 2011, 02:34 PM
Sorry ! I just realised that we are in the Silverlight forum while I should have posted this in the WinForms forum. I don't know how I ended here ... I will re-post this in the WinForms forum.
0
David
Top achievements
Rank 1
answered on 18 Jan 2012, 08:48 AM
Hello, I am facing the same problem, in this case the RadRibbonButton is inside the RadRibbonWindow/RadRibbonView/QuickAccessToolBar in OOB mode, current version is 2011.3.1309.1050.
And yes, the RadGridView.ActionOnLostFocus is explicitly set.
bests
0
Dimitrina
Telerik team
answered on 19 Jan 2012, 03:51 PM
Hello,

What is the value for the RadGridView.ActionOnLostFocus? Is it "None"?

 We were not able to get this same behaviour. Would it be possible for you to send us a small repro project to show us the case. That way we can be much more helpful.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
David
Top achievements
Rank 1
answered on 19 Jan 2012, 03:58 PM
Hello Didie, I'm instantiating the rgv programmatically like this:

var rgv = new RadGridView
{
 ValidatesOnDataErrors = GridViewValidationMode.None,
 IsFilteringAllowed = true,
 ShowGroupPanel = false,
 RowIndicatorVisibility = Visibility.Visible,
 IsReadOnly = false,
 CanUserFreezeColumns = true,
 EnableColumnVirtualization = true,
 EnableRowVirtualization = true,
 ActionOnLostFocus = ActionOnLostFocus.CommitEdit,
};


0
Dimitrina
Telerik team
answered on 20 Jan 2012, 01:29 PM
Hello,

 I was not able to get any problem with committing the data. Would you please describe in full details what "the same problem" is. Without a sample project to reproduce the issue I may not suggest you further.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Thomas
Top achievements
Rank 1
answered on 20 Jan 2012, 01:41 PM
I don't know if this can help you but when I posted  my own problem in the Winforms section, here's the answer I got in the end. I did not try temporary solution because I've been busy on other things that the related project these last weeks :

Reply from Telerik starts here:

(...) It seems that you have bind the RadGridView to IQueryable object. I added it to our public issue tracking system. It will be addressed in one of the next releases.
In the meantime, you can handle the update issue by simply changing the current row in that way:

protectedsealedoverridevoidBindingNavigator_SaveAction(objectsender)
{
    try
    {
        GridViewRowInfo row = this.countriesRadGridView.CurrentRow;
        this.countriesRadGridView.CurrentRow = null;
        this.countriesRadGridView.CurrentRow = row;
        this.DataContext.SaveChanges();
        base.FireUpdateData();
    }
    catch(Exception Ex)
    {
        stringexMessage = Ex.Message;
        MessageBox.Show(exMessage);
    }
}
0
MiddleTommy
Top achievements
Rank 1
answered on 20 Jan 2012, 02:27 PM
I think I have had a similar problem. How I solved it as a work around is make your save button get focus on mouse over. This will force the grid to loose focus and commit the edit before you save. RadMenuItems automatically do this.

pseudo
public void MouseOverButton(object sender...)
{
      var btn = sender as Button;
      btn.Focus();
}
Tags
GridView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Thomas
Top achievements
Rank 1
David
Top achievements
Rank 1
MiddleTommy
Top achievements
Rank 1
Share this question
or