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
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?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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.
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'. "
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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.)
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 >>
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"?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
And yes, the RadGridView.ActionOnLostFocus is explicitly set.
bests
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.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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,
};
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 >>
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:
protected
sealed
override
void
BindingNavigator_SaveAction(
object
sender)
{
try
{
GridViewRowInfo row =
this
.countriesRadGridView.CurrentRow;
this
.countriesRadGridView.CurrentRow =
null
;
this
.countriesRadGridView.CurrentRow = row;
this
.DataContext.SaveChanges();
base
.FireUpdateData();
}
catch
(Exception Ex)
{
string
exMessage = Ex.Message;
MessageBox.Show(exMessage);
}
}
pseudo
public void MouseOverButton(object sender...)
{
var btn = sender as Button;
btn.Focus();
}