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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
I've tried setting the EditException event on the cell and on the custom editor itself thinking that is what I missed.
TK
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