BUG ShowInsertRow="False" not respected

2 posts, 0 answers
  1. Simon
    Simon avatar
    57 posts
    Member since:
    May 2008

    Posted 11 Oct 2011 Link to this post


    I've found a bug with the ShowInsertRow property, which I hope you can fix ASAP.

    When setting  ShowInsertRow="False" in XAML, you can easily make it visible again after adding a new row.

    1. Hook up a RadButton as below...
    <telerik:RadButton Content="Add"
                                                       CommandTarget="{Binding ElementName=MyGridView}"
                                                       Width="45" />

    2. Now click the above button to insert a new row.
    3. Now click any column header to sort by that row.
    4. The ShowInsertRow is now visible.

    After further testing this seems to relate to when the AddingNewDataItem event is handled in the behind. The code below runs on insert then if you click cancel button  (via telerik:RadGridViewCommands.CancelRowEdit command) the ShowInsertRow is made visible.
    private void MyRadGridView_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e) 
        var grid = e.OwnerGridViewItemsControl;
        e.NewObject = ViewModel.CreateNewRecord(); 
        _newRecord = e.NewObject as MyObject; 
        //grid.CurrentColumn = grid.Columns[0];  //Causes an error on Save command 

    Also when you click save button (telerik:RadGridViewCommands.CommitEdit command) - an unhandled exception is thrown - due to the CurrentColumn being set. Take this last line out and you don't get the error!.
  2. Nedyalko Nikolov
    Nedyalko Nikolov avatar
    871 posts

    Posted 15 Oct 2011 Link to this post

    Hello Simon,

    We are aware of such behavior of the ShowInsertRow feature. I'll try to explain what causes the problem. When "Insert" key is pressed RadGridView should add a new item to the collection. The adding process has two parts (newObject creation and actual add to the collection). RadGridView raises AddingNewDataItem event and gives you an option to add default item (via e.NewObject property), if no item is supplied RadGridView tries to create a default object (via default parameter less constructor of the underlying business object). Second part of the job is adding new item to the source collection - when collection supports adding (IList or something like that) there is no problem item is added to the end of RadGridView items. When source collection doesn't implements IList then special UI for adding is displayed (same as ShowInsertRow = true). Indeed we can collapse this UI, but our assumption is that if the end user added one row probably he/she may want to add another new row. If you want to collapse this UI you can easily do that with a single line of code inside RowEditEnded event.

    void radGridView_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
                this.radGridView.ShowInsertRow = false;

    Unfortunately I cannot reproduce the described exception (setting CurrentColumn). Could you please send me a sample application which I can debug on my side in order to see what is going on?
    Thank you in advance.

    Nedyalko Nikolov
    the Telerik team

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

Back to Top