Esc in GridViewDateTimeColumn inside radDataGridView after I did an e.Cancel = true in Row Validation

4 posts, 1 answers
  1. ShareDocs
    ShareDocs avatar
    91 posts
    Member since:
    Oct 2012

    Posted 03 Sep 2013 Link to this post


    I am having a problem and had been searching the web and couldn't find anything that will help me.

    this is my problem.
    Im working in WinForm , c#

    I have a grid where is a Column of type **GridViewDateTimeColumn**.
    When the user update a row I check it in the event **RowValidating** and if I get a repeated date or other error I show the user a message and I do **e.cancel = true** to not validate the row.
    But then If I press ESC. I cannot cancel all the changes like it usually does before 
    Any idea how to do it?

    Here is my code:

       private void grdPirteyMenahel_RowValidating(object sender, RowValidatingEventArgs e)
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    if (e.Row != null)
                    {
      
    //Generate a service to connect to DB
                       
                       var factory = new MezumanimChannelFactory<IKerenService>(ServiceConsts.SERVICE_KEREN);
                       var service = factory.CreateChannel();
                       string sError = string.Empty;
    //here I call a SP in the database that check if the dates are correct (column of dates are call it "MiTaarich" and "AdTaarich".
    //The SP return a String with the error, if there is no error it will return and empty string
     
                       sError = GetErrorPirteySacharMenahel(Convert.ToDateTime(e.Row.Cells["MiTaarich"].Value), Convert.ToDateTime(e.Row.Cells["AdTaarich"].Value), Convert.ToInt32(e.Row.Cells["Kod"].Value));
     
                                    if (sError != string.Empty)
                                    {
                                        e.Cancel = true;
                                        RadMessageBoxHelper.Alert(sError);
                                    }
                       }
                           
                }
                catch (Exception ex)
                {
                     
                    Elad.Mezumanim.Client.Utils.Log.LogUtil.write(ex);
                    e.Cancel = true;
                    RadMessageBoxHelper.Alert(Messages.DataDisplayError, this);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }


    I also tried adding this code when i get the error:

     
    DataTable dt = (grdPirteyMenahel.DataSource as DataTable);
    dt.RejectChanges();


    But this recover the value of date as it was before (what is good) but doesn't let me get out of the row when I press ESC

    Any idea how to solve it?

    thank you very much
    best regards
    Iair
                                       
  2. Answer
    George
    Admin
    George avatar
    500 posts

    Posted 05 Sep 2013 Link to this post

    Hi Lior,

    Thank you for contacting us.

    Basically the RowValidating event's job is to prevent the user from leaving the row. You can implement your own custom solution which can work out in cases like this. Consider the below example:
    void grid_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
        if (editor != null)
        {
            object value= editor.Value ?? DateTime.Now;
            previousDateTime = (DateTime)value;
        }
    }
     
    DateTime previousDateTime;
    void grid_RowValidating(object sender, RowValidatingEventArgs e)
    {
        object value = e.Row.Cells[0].Value;
        if (value != null)
        {
            var a = (DateTime)value;
            if (a.Date.Year == 2013)
            {
                DialogResult res = RadMessageBox.Show("The inputed value is invalid, do you want to save it or revert it ?", "Invalid value", MessageBoxButtons.YesNo);
                if (res == System.Windows.Forms.DialogResult.No)
                {
                    e.Cancel = true;
                }
                else
                {
                    e.Row.Cells[0].Value = previousDateTime;
                }
            }
        }
    }

    I hope this information is helpful. If you need any further assistance, please let me know.
     
    Regards,
    George
    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. ShareDocs
    ShareDocs avatar
    91 posts
    Member since:
    Oct 2012

    Posted 09 Sep 2013 Link to this post



    Thanks George, this solve my problem.
    I would like that the GridViewDateTimeColumn do the revert alone when press the ESC key, like a regular column does.
    This is like a patch (not a real solution) but for the moment work for me.

    thank you very much.
    Best regards!
  4. George
    Admin
    George avatar
    500 posts

    Posted 11 Sep 2013 Link to this post

    Hello Lior,

    Thank you for replying.

    I have logged this in our Public Issue Tracking System. You can track for changes or comment/vote on this address - http://www.telerik.com/support/pits.aspx#/public/winforms/15725.

    I have also updated your Telerik Points for the report.

    If you need any more assistance I will be glad to help.
     
    Regards,
    George
    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 >>
Back to Top