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

Add new row after adding row

5 Answers 79 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Javier Gonzalez de Aragon
Top achievements
Rank 2
Javier Gonzalez de Aragon asked on 18 Oct 2013, 08:13 PM
Hello, I need the gridview to automatically go to the "new row" row and the first visible column (the first column is hidden) of that row after adding a row. How can I achieve this? I've tried the following but for some reason the selected column is the second, not the first one (NoMes).


Private Sub gvMeses_UserAddedRow(sender As Object, e As Telerik.WinControls.UI.GridViewRowEventArgs) Handles gvMeses.UserAddedRow
 
    gvMeses.MasterView.TableAddNewRow.IsCurrent = True
    gvMeses.Columns("NoMes").IsCurrent = True
 
End Sub

Thanks

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 22 Oct 2013, 02:42 PM
Hello Javier,

Thank you for writing.

This code seems to be working just fine on my end. Can you please make sure that column "NoMes" is indeed the first on in your grid, or just use the following code instead:
Private Sub gvMeses_UserAddedRow(sender As Object, e As Telerik.WinControls.UI.GridViewRowEventArgs) Handles gvMeses.UserAddedRow
  
    gvMeses.MasterView.TableAddNewRow.IsCurrent = True
    gvMeses.Columns(0).IsCurrent = True
  
End Sub

I hope this helps.

Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 22 Oct 2013, 07:05 PM
Same result, but after playing around a little bit, here's what I found. I had setup my grid to use the Enter key to move to the next cell instead of the next row. This is the ideal behavior for my grid. Using this configuration, if the Enter key is used to navigate the grid, when a row is added, instead of selecting the new row, the first row is selected. If the Tab key is used to navigate the grid, when a row is added, the new row is indeed selected, but the second column is selected instead of the first column. If the grid is setup to use the Enter key to move to the next row, then after a row is added the new row is selected and also the first column, but this is the only scenario that it works, and as you can imagine, it is far from ideal.
0
Accepted
Stefan
Telerik team
answered on 25 Oct 2013, 08:38 AM
Hello Javier,

The NewRowEnterKeyMode was the reason for the different behavior on both ends. To achieve the desired navigation you will have to create a descendant of GridNewRowBehavior and override the Enter and Tab key behavior. Here is a sample implementation:
class MyNewRowBehavior : GridNewRowBehavior
{
    protected override bool ProcessEnterKey(KeyEventArgs keys)
    {
        bool isAtLastColumn = this.Navigator.IsLastColumn(this.GridControl.CurrentColumn);
 
        bool result = base.ProcessEnterKey(keys);
 
        bool isAtFirstColumn = this.Navigator.IsFirstColumn(this.GridControl.CurrentColumn);
 
        if (isAtLastColumn && isAtFirstColumn)
        {
            this.GridControl.MasterView.TableAddNewRow.IsCurrent = true;
            this.GridControl.Columns[0].IsCurrent = true;
        }
 
        return result;
    }
 
    protected override bool ProcessTabKey(KeyEventArgs keys)
    {
        bool isAtLastColumn = this.Navigator.IsLastColumn(this.GridControl.CurrentColumn);
 
        bool result = base.ProcessTabKey(keys);
 
        bool isAtFirstColumn = this.Navigator.IsFirstColumn(this.GridControl.CurrentColumn);
 
        if (isAtLastColumn && isAtFirstColumn)
        {
            this.GridControl.MasterView.TableAddNewRow.IsCurrent = true;
            this.GridControl.Columns[0].IsCurrent = true;
        }
 
        return result;
    }
}

And here is how to put this class in action:
((BaseGridBehavior)radGridView1.GridBehavior).UnregisterBehavior(typeof(GridViewNewRowInfo));
((BaseGridBehavior)radGridView1.GridBehavior).RegisterBehavior(typeof(GridViewNewRowInfo),new MyNewRowBehavior() );

I hope this helps.

Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 31 Oct 2013, 12:47 AM
Exactly what I was looking for.

Thanks.
0
David
Top achievements
Rank 1
answered on 11 Mar 2014, 01:24 PM
I did exactly the same but not working !!!! plz help its too important?
Tags
GridView
Asked by
Javier Gonzalez de Aragon
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Javier Gonzalez de Aragon
Top achievements
Rank 2
David
Top achievements
Rank 1
Share this question
or