Change CurrentRow on/after cancelling UserAddingRow

3 posts, 1 answers
  1. Bjoern
    Bjoern avatar
    2 posts
    Member since:
    Jun 2015

    Posted 18 Jan Link to this post

    Hi,

    I have a problem with unselecting the new Row in my grid.

    To explain the problem, i have a grid, where the user can add data to by using the new Row.

    When clicking the new Row, it gets populated with some default data and can be edited.

    I wanted to make sure the edited data gets saved when the user leaves the new Row,

    so i used the UserAddingRow event to open a MessageBox to ask the user if he wants to save.

    If yes, all right.

    If no, I use e.Cancel to reject the data.

    => At this point I would like the new Row to change back to the initial "Click here to add new row" state,

    but it stays selected or defined as CurrentRow. The data is gone, but an empty row stays as long as I don't switch to

    another row manually, even when the data bound to the grid changes.

    I can't find a way to unselect the row or set CurrentRow = null, as it seems not to be possible out of the event.

    Also there seems to be no other event to hook up to after UserAddingRow when cancelled.

     

    Maybe there is an easy way of unselecting, or maybe I'm using the wrong event for that purpose.

    I would be glad for some help. :)

      

    01.private void RadGridViewClockTimeUserAddingRow(object sender, GridViewRowCancelEventArgs e)
    02.        {
    03.            var result = RadMessageBox.Show(
    04.                this,
    05.                Resources.DoYouWantToSaveNew,
    06.                Resources.Save,
    07.                MessageBoxButtons.OKCancel);
    08. 
    09.            if (result == DialogResult.OK) return;
    10. 
    11.            e.Cancel = true;
    12.            // CurrentRow = null ??
    13.        }

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 19 Jan Link to this post

    Hello Bjoern,

    Thank you for writing.

    By default when the adding is canceled the grid keeps the focus on the new row. So you can clear the current row after some time. For example:
    public Form1()
    {
        InitializeComponent();
        
        timer.Interval = 200;
        timer.Tick += Timer_Tick;
    }
     
    Timer timer = new Timer();
     
    private void Timer_Tick(object sender, EventArgs e)
    {
        radGridView1.CurrentRow = null;
        timer.Stop();
    }
    private void RadGridView1_UserAddingRow(object sender, GridViewRowCancelEventArgs e)
    {
        e.Cancel = true;
        timer.Start();
    }

    Let me know if you have additional questions.

    Regards,
    Dimitar
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bjoern
    Bjoern avatar
    2 posts
    Member since:
    Jun 2015

    Posted 19 Jan Link to this post

    Hi Dimitar,

    thanks for the quick reply.

    It's not the first way I thought about, but it does the trick.

    Thanks for helping me out!

     

    Best, Björn

     

Back to Top