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

RadGridView (RowValidating Event)

9 Answers 433 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Flavio
Top achievements
Rank 1
Flavio asked on 02 Jul 2013, 06:06 PM
Hi,

I am having trouble using the RadGridView (RowValidating Event).

When the RowValidating is fired, the values of my new row to be added are checked,
if one of them is not okay, the message is shown to remind the user to input the correct values.

The problem is:
- if I don´t want to add this new row, how do I discard it?
(in the case I have all cells, for this new row, with null values)

I have the "e. Row. Cancel = true" to try to cancel de adding, and it works,
but the problem is that the phrase "Click here to add a new row" is not set
back to the top, and any other values (Cells) that is in the grid can´t be edited,
it got stuck, until I finish adding this row.

If I erase my "RowValidating" and try again, the problem is solved.

Is it possible to discard a new row
if I have a "RowValidating" on, and once it´s canceled,
to have the phrase "Click here to add a new row" back on top to start over a new adding?

Thanks for your help.

9 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 05 Jul 2013, 11:26 AM
Hi Flavio,

Thank you for writing.

You can cancel the adding of a new row in the grid by using the following method:
radGridView1.MasterView.TableAddNewRow.CancelAddNewRow();

To make the new row current, set its IsCurrent property:
radGridView1.MasterView.TableAddNewRow.IsCurrent = true;

I hope that you find this information useful.
 

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
Vijay
Top achievements
Rank 1
answered on 30 Aug 2013, 01:07 AM
I am having a similar issue. 
I have RowValidating on my RadGridView and want to be able to handle the ESCAPE KEY as a cancel/abort - so that the would-be added row can be removed and the action can be backed out. 
It is locking up my program due to the expected/forced user input in the row. 

How do I determine if the Escape Key has been pressed at the time of RowValidating, and how do I abort the RowValidating. 
Should I check if the row is empty (is there a best way for this?) and then allow the validating to pass as true so that the escape key works? Would this add a row or continue with the escape key function of cancel? 

Thanks for your time.
Vijay
0
Stefan
Telerik team
answered on 03 Sep 2013, 09:42 AM
Hi Vijay,

Thank you for writing.

To capture the Escape key press you can use the PreviewKeyDown event, where you can raise a flag which will be used in the RowValidating event to prevent the validation cancellation:
bool quitValidating = false;
 void radGridView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
 {
     if (e.KeyData == Keys.Escape)
     {
         quitValidating = true;
     }
 }
 
 void radGridView1_RowValidating(object sender, RowValidatingEventArgs e)
 {
     if (quitValidating == true)
     {
         quitValidating = false;
         return;
     }
 
     if (e.Row != null && e.Row.Cells[0].Value == null)
     {
         e.Cancel = true;
     }
 }

Please give this approach a try and let me know how it works for you.
 
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
Kristoffer
Top achievements
Rank 1
answered on 31 Oct 2013, 12:48 PM
For me, the "new row" is not updated when I call "CancelAddNewRow()". So, in RowValidating event I have this:

e.Cancel = true;
radGridView1.MasterView.TableAddNewRow.CancelAddNewRow();
radGridView1.MasterView.TableAddNewRow.IsCurrent = true;

Same problem. The new row is blocking user input. I just want to remove it!


UPDATE
Hmm, IsCurrent = false does the trick. Is there a typo?
0
Stefan
Telerik team
answered on 01 Nov 2013, 07:23 AM
Yes there is a typo. You need to make the NewRow not current in order to make it display the "Click here to add new row text".

Please excuse me for the introduced confusion.
 
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
Marek Kruk
Top achievements
Rank 1
answered on 21 Feb 2014, 11:41 AM
Hello, I have the same problem. My grid blocks after:

Private Sub RadGridView1_RowValidating(sender As Object, e As Telerik.WinControls.UI.RowValidatingEventArgs) Handles RadGridView1.RowValidating
 
    e.Cancel = True
    RadGridView1.MasterView.TableAddNewRow.CancelAddNewRow()
    RadGridView1.MasterView.TableAddNewRow.IsCurrent = False
 
End Sub

What
am I doing wrong?
(UI for WinForms Q3 2013 SP2)

Regards,
Marek
0
Stefan
Telerik team
answered on 24 Feb 2014, 07:34 AM
Hi Marek,

RowValidating is being fired when an attempt to change the current row of the grid is made or when the control looses focus. So, this code will always prevent the current row from being changed and will discard the changes to the new row and will mark it as NOT current, in order to display its text. You need to have some validation logic and to use this code when it fails.

I hope this helps. 

Regards,
Stefan
Telerik
0
Jeff
Top achievements
Rank 1
answered on 03 Mar 2014, 07:22 AM
[quote]Stefan said:Hi Flavio,

Thank you for writing.

You can cancel the adding of a new row in the grid by using the following method:
radGridView1.MasterView.TableAddNewRow.CancelAddNewRow();

To make the new row current, set its IsCurrent property:
radGridView1.MasterView.TableAddNewRow.IsCurrent = true;

I hope that you find this information useful.
 

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 >>
 
[/quote]

Where is this documented?  I can't find anything about this in the validation documentation for GridView.
0
Stefan
Telerik team
answered on 03 Mar 2014, 01:00 PM
Hi Jeff,

Currently, this property is available only in the API documentation here: http://www.telerik.com/help/winforms/m_telerik_wincontrols_ui_gridviewnewrowinfo_canceladdnewrow.html. In future documentation updates, we will consider adding it in the contextual documentation as well. 

I have updated your Telerik Points for this suggestion. 

Regards,
Stefan
Telerik
Tags
GridView
Asked by
Flavio
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Vijay
Top achievements
Rank 1
Kristoffer
Top achievements
Rank 1
Marek Kruk
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Share this question
or