Hi!
I have a ultragrid, and in one of its cells i've set up a mask, like this :
UltraGridColumn column = ulgPricesBudget.DisplayLayout.Bands[0].Columns["FY"]; column.MaskInput = "20##"; column.MaskDataMode = MaskMode.IncludeBoth; column.MaskDisplayMode = MaskMode.IncludeBoth;
column.MaskInput = "20##";
column.MaskDataMode = MaskMode.IncludeBoth;
column.MaskDisplayMode = MaskMode.IncludeBoth;
In the BeforeExitEditMode I do a check :
if (ulgPricesBudget.ActiveCell.Column.Key == "FY" && ulgPricesBudget.ActiveCell.EditorResolved.Value.ToString() != "") { ..... }
So the mask is like this "20__" - it's an year.
This is the code line that throws an exception if i insert in the masked cell a value like "20_1" (i insert just the last character the "1"). The exception is :
Internal error: can't get masked editor value. Inner exception is: Input does not match the mask.
What am i doing wrong ?
Could you help me in this issue ?
Thanks!
you can handle it in the celldataerror event by forcing the user to stay in edit mode until he puts the first number
private void ultraGrid1_CellDataError(object sender, CellDataErrorEventArgs e)
{
e.StayInEditMode = true;
e.RaiseErrorEvent = false;
}
Thanks, but i tried it and nothing changed...
Hi,
I'm not sure what you are asking. What do you want the behavior to be?
I assume you don't want the Exception to be displayed to the user, but what do you want?
Is the CellDataError event firing?
What's the DataType of the column?
Hi Mike !
I want to be able to throw an exception if the cell has invalid data - this means catching the cellDataEvent and display a message to the user. At this moment, the event doesn't trigger, i just get an exception when reffering to
ulgPricesBudget.ActiveCell.EditorResolved.Value.ToString()
The exception is the one mentioned in the previous post. I'm doing this refference in the BeforeExitEditMode - so i'm not sure what's the events triggering order - first CellDataError and then BeforeExitEditMode ?
If accessing "ulgPricesBudget.ActiveCell.EditorResolved.Value" causes an exception, it means that the text the user entered into the cell is not valid and that the CellDataError event will fire - probably after the cell Exit's Edit mode.
So in a case like this, the user will see the error message, anyway, and you don't need to do anything in your code. So there's no reason for you to manually try to validate the data against the mask.
I assume what you are trying to do here is to add some additional validation in case the user types something that is valid for the mask, but not valid for your application.
So what I would probably do is check this:
ulgPricesBudget.ActiveCell.EditorResolved.IsValid
If this is false, then you know that what the user entered is not valid for the mask or for some other reason (such as DataType) and the CellDataError event is going to fire and you don't need to bother validating.
If IsValid is true, then you can go ahead and validate it against your own criteria.
Thanks Mike!
This solved my problem :)