This is a migrated thread and some comments may be shown as answers.

IsValid or IsContentValid on Cells - Neither works!

3 Answers 32 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rachel
Top achievements
Rank 2
Rachel asked on 07 Oct 2010, 02:27 AM
I just upgraded to Q2 2010 SP2, and noticed that the IsContentValid property for GridViewCells has been replaced with IsValid.  Ok, so I changed to the new property, and started testing.

But it seems that neither of these properties (the old obsolete one, or the new one) is False when there is an invalid entry in a cell.  IsContentValid used to be false when the user had entered text in a numeric field, for example, before my upgrade.  But now both fields are always true, even when I can see an error showing on the cell. 

For the image attached, even though the error is clearly visible, the IsValid (and also IsContentValid) for that cell are both still true!

I need to be able to detect if a cell has errors, because some operations I do not allow while there is an invalid input.  What property works for this now?

Thanks!
Rachel

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 08 Oct 2010, 06:10 PM
Hello Rachel,

Indeed we've changed validation logic a little bit, and I'm really sorry about that. I'll try to explain you why we do so.
When cell.IsValid property is set to false a red border will appear around the wrong cell, but in a scenario like yours also another red border will surround editing element (in that case TextBox). So we will have two red borders which with default RowHeight is not a problem but when RowHeight is set to a greater value there is a problem. The solution is simple to remove one red border and in we remove it from GridViewCell. However this red border will appear if you set cell.IsValid = false, or any error is received via INotifyDataErrorInfo and IDataErrorInfo interface.

You can replace check for IsValid state of the cell with a check for e.ValidationResult property inside CellValidated event (after data layer validation). Let me know if this doesn't help.

Kind regards,
Nedyalko Nikolov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rachel
Top achievements
Rank 2
answered on 08 Oct 2010, 06:18 PM
Thank you for replying.

Your answer does help explain it, but it does not really solve my situation.  I don't want to just check the cell status when it validates, I want to be able to check it any time.  I have worked around the issue by watching the validation event and manually setting IsContentValid (the 'obsolete' property) in the handler, and then checking IsContentValid whenever I need to.

It seems that IsValid doesn't really replace IsContentValid at all, but instead performs an entirely different function.  When the compiler warnings tell me a property is replaced, I would expect it to work the same way.  It would be nice to have IsContentValid back, or some other method to check if a cell has errors, regardless of visual elements.  Although my workaround works, it is not ideal, because I still get warned that the property is obsolete.

Also, I am confused about what possible scenario IsValid would ever be false, and what purpose it would serve if not to tell me about invalid inputs?

Thanks again,
Rachel
0
Nedyalko Nikolov
Telerik team
answered on 11 Oct 2010, 03:32 PM
Hello Rachel,

We will add HasValidationErrors() method to GridViewCellBase class which will allow you to meet your goals. Meanwhile you can call same method as extension method:

public static class GridViewCellExtensions
    {
        public static bool HasValidationErrors(this GridViewCellBase cell)
        {
            List<UIElement> visualElements = cell.ChildrenOfType<UIElement>().ToList();
            foreach (var item in visualElements)
            {
                if (Validation.GetHasError(item))
                {
                    return true;
                }
            }
            return false;
        }
    }

Let me know if this doesn't help.

Kind regards,
Nedyalko Nikolov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Rachel
Top achievements
Rank 2
Answers by
Nedyalko Nikolov
Telerik team
Rachel
Top achievements
Rank 2
Share this question
or