简体   繁体   中英

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

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

Ok, I asked Telerik about it, and theY gave me a solution. its not a real solution its more like a patch a workaround but for the moment its good for me.

http://www.telerik.com/community/forums/winforms/gridview/esc-in-gridviewdatetimecolumn-inside-raddatagridview-after-i-did-an-e-cancel-true-in-row-validation.aspx

thanks Iair

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM