This question is locked. New answers and comments are not allowed.
normalham2
Top achievements
Rank 1
normalham2
asked on 15 Oct 2009, 03:07 PM
Is there a way to set a cell to IsValid = false, outside of the CellValidating event? In other words, get that nice invalid image within the cell.
I don't think Data Annotations is ready yet from attempting to get this to work. (I have the latest internal build). Basically, I'm doing validation in my view model, and I have to perform database access for a few cells. The CellValidating event is a little tough to get that to work in an asynch way with the view model approach. Any general suggestions are welcome.
Thanks,
Todd
I don't think Data Annotations is ready yet from attempting to get this to work. (I have the latest internal build). Basically, I'm doing validation in my view model, and I have to perform database access for a few cells. The CellValidating event is a little tough to get that to work in an asynch way with the view model approach. Any general suggestions are welcome.
Thanks,
Todd
Edit: 10/19/2009 - I'm going to create a Telerik Support Ticket to help me with this issue. I'll update this post once I find a solution.
3 Answers, 1 is accepted
0
Hi normalham2,
I paste my answer from your support ticket in order to be available for other members of Telerik community.
You can set GridViewCell.IsContentValid property to false in order to get this working.
Unfortunately with the next official release we will change a little validation mechanism due to support for the validation attributes in Data Annotations assembly. Invalid state of the GridViewCell will be visible only when GridViewCell is in edit mode as part of the EditorPresenter, but only one cell can be in edit mode (for now).
Our beta 2 is now released and Data Annotations support is available (there are some issues related to validation which will be fixed with the Friday internal build related to Q3 beta 2). Please give it a try, I'll be glad to assist if you have further questions (issues).
Best wishes,
Nedyalko Nikolov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I paste my answer from your support ticket in order to be available for other members of Telerik community.
You can set GridViewCell.IsContentValid property to false in order to get this working.
Unfortunately with the next official release we will change a little validation mechanism due to support for the validation attributes in Data Annotations assembly. Invalid state of the GridViewCell will be visible only when GridViewCell is in edit mode as part of the EditorPresenter, but only one cell can be in edit mode (for now).
Our beta 2 is now released and Data Annotations support is available (there are some issues related to validation which will be fixed with the Friday internal build related to Q3 beta 2). Please give it a try, I'll be glad to assist if you have further questions (issues).
Best wishes,
Nedyalko Nikolov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mily
Top achievements
Rank 1
answered on 03 Nov 2009, 03:53 PM
Hi Nedyalko ,
I think I agree with normalham2. I don't think data annotations are ready just yet. I don't want to throw exception when cell data is committed to the business object neither. Our business objects don't throw validation exception in property setter but keep track of broken rules in a collection (default behaviour for CSLA.NET). When CellValidating event is raised validation rules for the property being set have not been checked yet. Therefore we would need to set e.IsValid = false in the CellValidated (after cell value is committed to the underlaying business object). Please note committing invalid data to the business object is not a problem as it implements IEditableObject so canceling edit of the invalid object will call CancelEdit (which rolls back all the changes). I had a quick look at your code and found that changing following code:
to (roughly)
private static bool ValidateCell(GridViewCell cell)
{
GridViewCellValidatingEventArgs args = RaiseCellValidatingEvent(cell);
List<ValidationError> list = null;
if (isValid)
{
list = cell.UpdateSourceWithEditorValue();
}
GridViewCellValidationResult validationResult = new GridViewCellValidationResult();
if ((list != null) && (list.Count > 0))
{
StringBuilder builder = new StringBuilder();
foreach (ValidationError error in list)
{
builder.AppendLine(error.ErrorContent.ToString());
}
validationResult.ErrorMessage = builder.ToString();
validationResult.PropertyName = cell.DataColumn.GetDataMemberName();
args.IsValid = false;
}
// GridViewCellValidatedEventArgs would require IsValid property as well
GridViewCellValidatedEventArgs e = new GridViewCellValidatedEventArgs(GridViewDataControl.CellValidatedEvent, validationResult, cell, cell.EditorPresenter.Content, args.IsValid);
cell.ParentDataControl.RaiseEvent(e);
cell.EditorPresenter.IsContentValid = e.IsValid;
cell.EditorPresenter.ErrorMessage = e.IsValid ? null : e.ValidationResult.ErrorMessage;
return e.IsValid;
}
would provide a way to provide the functionality we are after.
Best Regards
Milosz
I think I agree with normalham2. I don't think data annotations are ready just yet. I don't want to throw exception when cell data is committed to the business object neither. Our business objects don't throw validation exception in property setter but keep track of broken rules in a collection (default behaviour for CSLA.NET). When CellValidating event is raised validation rules for the property being set have not been checked yet. Therefore we would need to set e.IsValid = false in the CellValidated (after cell value is committed to the underlaying business object). Please note committing invalid data to the business object is not a problem as it implements IEditableObject so canceling edit of the invalid object will call CancelEdit (which rolls back all the changes). I had a quick look at your code and found that changing following code:
private static bool ValidateCell(GridViewCell cell) |
private static bool ValidateCell(GridViewCell cell)
{
GridViewCellValidatingEventArgs args = RaiseCellValidatingEvent(cell);
List<ValidationError> list = null;
if (isValid)
{
list = cell.UpdateSourceWithEditorValue();
}
GridViewCellValidationResult validationResult = new GridViewCellValidationResult();
if ((list != null) && (list.Count > 0))
{
StringBuilder builder = new StringBuilder();
foreach (ValidationError error in list)
{
builder.AppendLine(error.ErrorContent.ToString());
}
validationResult.ErrorMessage = builder.ToString();
validationResult.PropertyName = cell.DataColumn.GetDataMemberName();
args.IsValid = false;
}
// GridViewCellValidatedEventArgs would require IsValid property as well
GridViewCellValidatedEventArgs e = new GridViewCellValidatedEventArgs(GridViewDataControl.CellValidatedEvent, validationResult, cell, cell.EditorPresenter.Content, args.IsValid);
cell.ParentDataControl.RaiseEvent(e);
cell.EditorPresenter.IsContentValid = e.IsValid;
cell.EditorPresenter.ErrorMessage = e.IsValid ? null : e.ValidationResult.ErrorMessage;
return e.IsValid;
}
would provide a way to provide the functionality we are after.
Best Regards
Milosz
0
Hello Mily,
Thank you for the feedback. You can hook for the CellValidating event and manually update your business object with the value from eventArgs.NewValue. This will trigger CSLA validation and will complete validation process, so you can get errors and display them properly.
Of course we will consider your proposal about adding "IsValid" property to the GridViewCellValidatedEventArgs, which at first sight seems very nice.
P.S. I've updated your Telerik points accordingly.
Best wishes,
Nedyalko Nikolov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thank you for the feedback. You can hook for the CellValidating event and manually update your business object with the value from eventArgs.NewValue. This will trigger CSLA validation and will complete validation process, so you can get errors and display them properly.
Of course we will consider your proposal about adding "IsValid" property to the GridViewCellValidatedEventArgs, which at first sight seems very nice.
P.S. I've updated your Telerik points accordingly.
Best wishes,
Nedyalko Nikolov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.