Menu

Custom editor exceptions not handled

Help
TGK
2006-10-05
2013-04-23
  • TGK

    TGK - 2006-10-05

    Davide,

    I'm working on a custom editor that will validate values and eventually automatically change other cell values.

    When I throw a new SourceGrid.SourceGridException I get an exception that indicates that the SourceGridException is not being handled.  The exact message is:  "SourceGridException was unhandled by user code.".  I assume this means that the exception is not being handled by your code that is calling GetEditedValue ?????

    Here is the GetEditedValue method....

            public override object GetEditedValue()
            {
                string value = Control.Text;
                int iValue = 0;
                try
                {
                    iValue = int.Parse(value);
                    if (iValue < 0 || iValue > 100)
                    {
                        throw (new SourceGrid.SourceGridException("Weight must be between 0 and 100"));
                    }
                }
                catch (Exception ex)
                {
                    throw (new SourceGrid.SourceGridException(ex.Message));
                }
                return (Control.Text);
            }

    Thanks,
    Terry

     
    • TGK

      TGK - 2006-10-05

      I've tried setting the EditException event on the cell and on the custom editor itself thinking that is what I missed.

      TK

       
    • Davide Icardi

      Davide Icardi - 2006-10-05

      Hi,

      I suggest to don't use the GetEditedValue but to override the OnValidating method.
      This is the right method to place validation or conversion. I think that baiscally you can
      Here you can set the Cancel = true property of the ValidatingCellEventsArgs or throw an exception.

      In the GetEditedValue returns the Text value and make the conversion in the OnValidating event.

      Usually inside the windows controls events an exception is not automatically catched, so this cause an unhandled error.

      Davide

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.