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

when adding a new row, the RowEditEnded event fires before the new row appears

6 Answers 326 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jorge Alberto
Top achievements
Rank 1
Jorge Alberto asked on 21 Jul 2010, 05:08 PM
Hello :)

I have a problem when I try to add a new row to the gridview,  

In short, I have an empty gridview and the event RowEditEnded fires before the new row appears for editing and without the user presses enter when adding a new row into the gridview when the grid view is not empty (when the gridview is empty RowEditEnded event fires after the user presses enter).

My scenario is the following:

When the gridview is empty, I use the BeginInsert() method to insert a new row, then the handler for the AddingNewDataItem gets executed, then appears a new row on the gridview with the first cell on edit mode, then I fill all the cells on the gridview and after that I hit enter, after I press enter the handler for the RowEditEnded event gets executed with e.EditOperationType==Insert  and e.EditAction==Commit, (in this handler I add the new row to a data base) and so far so well, but when I want to insert an other new row, the handler for the AddingNewDataItem event gets executed and just after that (and here is the problem) the handler for the RowEditEnded event gets executed with e.EditOperationType==Insert and e.EditAction==Commit (without the new row appears for editing and without the user presses enter) and after that the row appears on the grid view ready for editing (also for default appears the last cell of the row in edit mode and for this reason I have to press esc and go to the first cell of the row), so the RowEditEnded event fires before the new row appears for editing and without the user presses enter.

Is this the default behavior or am I doing something wrong? 

void NuevoProveedorButton_Click(object sender, RoutedEventArgs e)
{
            this.ProveedoresGridView.BeginInsert();
}
 
void ProveedoresGridView_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
{
            e.NewObject = new Proveedor_TipoProveedor();
}




6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 22 Jul 2010, 04:29 PM
Hello Jorge Alberto,

The thing is that the cell set into edit-mode in the new row corresponds to the cell that has been lastly selected. In order to dismiss that behavior, you can set the property of the grid CurrentColumn to the first one. For example:

private void Button1_Click(object sender, RoutedEventArgs e)
{
     this.playersGrid.CurrentColumn =          this.playersGrid.Columns.OfType<GridViewColumn>().First();
     this.playersGrid.BeginInsert();
}

As for the firing of the RowEditEnded event right after the AddingNewDataItem without clicking the "Enter" key, I was not able to reproduce it. So, in case the proposed workaround does not meet your requirements, please provide more details about your project and its settings.
 

Greetings,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jorge Alberto
Top achievements
Rank 1
answered on 22 Jul 2010, 07:28 PM
Hello Maya, 

Thank you very much for your answer.
 
I will give you more details about my project because the firing of the RowEditEnded event right after the AddingNewDataItem without clicking the "Enter" key, is really happening. I already figure out a workaround to deal with it (some sort of if/else logic) because I can't stop the development of my project.

Best Regards,
Jorge
0
Maya
Telerik team
answered on 28 Jul 2010, 11:15 AM
Hi Jorge Alberto,

We are looking forward to more details about your project so that we could provide you with an appropriate solution.
Thank you for your time.
 

Best wishes,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jorge Alberto
Top achievements
Rank 1
answered on 10 Sep 2010, 06:22 PM
Hello Maya :)

Finally, I have figured out when the RowEditEnded fires just after the BeginInsert() method executes without pressing enter.

If the gridview has a row selected and I want to create a new row, the RowEditEnded fires just after the BeginInsert() method executes, without pressing enter.

But, if the gridview has no row selected i.e. there is no row in the gridview marked and colored as selected, and I want to create a new row, the RowEditEnded fires when I press enter after I have finished to edit the row, i.e. the normal behavior.

The gridview ItemSource property is bound to a ObservableCollection of linq to sql objects.
To create a new row I click a button and the eventhandler of this button calls the BeginInsert() method.

I hope you can reproduce this, because it is actually happening.

Best regards, Jorge
0
Jorge Alberto
Top achievements
Rank 1
answered on 10 Sep 2010, 06:34 PM
Hello Maya :)

Additional information about the previous reply:

Clearing the selectedItems collection or setting to null the selectItem of the GridView before calling the BeginInsert() method like this:
void NewRowButton_Click(object sender, RoutedEventArgs e)
        {
            GridView.SelectedItem = null;
            GridView.SelectedItems.Clear();
            GridView.BeginInsert();
        }
 doesn´t make any change.

The behavior explained on the previous reply remains.

Best Regards, Jorge.
0
Maya
Telerik team
answered on 13 Sep 2010, 03:46 PM
Hello Jorge Alberto,

Unfortunately, even though I followed the scenario you proposed - selecting an item and then inserting a new one - I was not able to reproduce the issue. I am sending you the sample project I have tested the problem on. Please feel free to modify it in the way you need and share any details in case there is some misunderstanding according to your requirements.

 

All the best,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Jorge Alberto
Top achievements
Rank 1
Answers by
Maya
Telerik team
Jorge Alberto
Top achievements
Rank 1
Share this question
or