Add new row after adding row

6 posts, 1 answers
  1. Javier Gonzalez de Aragon
    Javier Gonzalez de Aragon avatar
    35 posts
    Member since:
    Mar 2010

    Posted 18 Oct 2013 Link to this post

    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
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 22 Oct 2013 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Javier Gonzalez de Aragon
    Javier Gonzalez de Aragon avatar
    35 posts
    Member since:
    Mar 2010

    Posted 22 Oct 2013 Link to this post

    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.
  5. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 25 Oct 2013 Link to this post

    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 >>
  6. Javier Gonzalez de Aragon
    Javier Gonzalez de Aragon avatar
    35 posts
    Member since:
    Mar 2010

    Posted 30 Oct 2013 Link to this post

    Exactly what I was looking for.

    Thanks.
  7. David
    David avatar
    5 posts
    Member since:
    Jan 2012

    Posted 11 Mar 2014 Link to this post

    I did exactly the same but not working !!!! plz help its too important?
Back to Top
UI for WinForms is Visual Studio 2017 Ready