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

CellValidation event fires twice

3 Answers 174 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Francois
Top achievements
Rank 1
Francois asked on 19 Jan 2011, 02:29 PM
I show a message box in cellvalidating event to show the error message as a Messagebox..

It usually work ok, but if i use the TAB key to move out of the field, the event fire twice (so the message box show twice... )


A sample project is attached to the support ticket #384333
http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=384333

3 Answers, 1 is accepted

Sort by
0
Yordanka
Telerik team
answered on 20 Jan 2011, 02:17 PM
Hello Francois,

Please, find our reply in the other forum thread started by you.

Regards,
Yordanka
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Scott Michetti
Top achievements
Rank 1
answered on 27 Nov 2012, 08:08 PM
I'm having the same issue. So can you show the solution? I couldn't find the other thread you refer to.

Thanks
Scott
0
Yordanka
Telerik team
answered on 28 Nov 2012, 07:26 AM
Hello Scott,

The problem comes from the fact that MessageBox gets the focus after TAB key is pressed. So, CommitEdit() is called and respectively CellValidating() is fired again. To avoid this, you have two options - either to set ActionOnLostFocus to None or to show validation message in this way:

private void ctlTelerik_CellValidating(object sender, Telerik.Windows.Controls.GridViewCellValidatingEventArgs e)
        {
            if (e.NewValue.ToString().Length > 4)
            {
                e.IsValid = false;
                //MessageBox.Show("Username too long");
                e.ErrorMessage = "Username too long";
            }
        }

 

Regards,
Yordanka
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Francois
Top achievements
Rank 1
Answers by
Yordanka
Telerik team
Scott Michetti
Top achievements
Rank 1
Share this question
or