This is a migrated thread and some comments may be shown as answers.
Change CurrentRow on/after cancelling UserAddingRow
2 Answers 19 Views
This is a migrated thread and some comments may be shown as answers.
Bjoern
Top achievements
Rank 1
Bjoern asked on 18 Jan 2016, 04:38 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 19 Jan 2016, 09:16 AM
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
0
Bjoern
Top achievements
Rank 1
answered on 19 Jan 2016, 12:02 PM

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

 

Asked by
Bjoern
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Bjoern
Top achievements
Rank 1
Share this question
or