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

Validation highlights wrong cell in some situations

2 Answers 7 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Cory
Top achievements
Rank 1
Cory asked on 25 Nov 2015, 09:50 PM

On RowValidating, when a GridViewCellValidationResult is added with a PropertyName such as "Hours", and a column that precedes the Hours column has a binding path of say "SourceHours", the GridView logic incorrectly does a .Contains() on the PropertyName to get the cell, which leads to the SourceHours column being highlighted as the one with the validation error, instead of the Hours column.

I'm using Telerik.Windows.Controls.GridView, Version=2015.3.1104.45, and the offending method is Telerik.Windows.Controls.GridView.GridViewRow.TryGetCellFromPropertyName.

Here's the relevant XAML:

                    <telerik:GridViewDataColumn Header="Source Hours" DataMemberBinding="{Binding SourceHours}" DataFormatString="n" TextAlignment="Right" />

                    <telerik:GridViewDataColumn Header="Hours" DataMemberBinding="{Binding Hours}" DataFormatString="n" TextAlignment="Right" />

And here is how I'm adding the GridViewCellValidationResult in the RowValidating event handler:

if (attendance.Hours == 0m) {

    e.ValidationResults.Add(new GridViewCellValidationResult { PropertyName = "Hours", ErrorMessage = "Hours cannot be zero."});

}

And this is why it's failing ( the Contains(this.propertyName) part):

internal bool TryGetCellFromPropertyName(string propertyName, out GridViewCell gridViewCell)
        {
            Func<GridViewBoundColumnBase, bool> func = (GridViewBoundColumnBase c) => c.GetDataMemberName().Contains(this.propertyName);
            GridViewDataControl gridViewDataControl = base.GridViewDataControl;
            if (string.IsNullOrEmpty(propertyName) || gridViewDataControl == null)
            {
                gridViewCell = null;
                return false;
            }
            gridViewCell = (
                from c in base.Cells.OfType<GridViewCell>()
                where c.DataColumn != null
                select c).FirstOrDefault<GridViewCell>((GridViewCell c) => func(c.DataColumn));
            return gridViewCell != null;
        }

If it instead was coded as c.GetDataMemberName() == this.propertyName (or similarly ignoring case if desired), it seems to me that it would work as expected.

For now I will use a UniqueName to get around the issue, but I wanted to bring it to Telerik's attention.

2 Answers, 1 is accepted

Sort by
0
Cory
Top achievements
Rank 1
answered on 25 Nov 2015, 10:03 PM
Actually I'm not able to work around the issue, since the Telerik code does not use the UniqueName unless the name cannot be obtained from the binding.  In my case the binding path provides the name so UniqueName is ignored.
0
Accepted
Dilyan Traykov
Telerik team
answered on 27 Nov 2015, 03:13 PM
Hello Cory,

Thank you for reporting this issue, I can confirm that it is a bug on our side. I have logged it in our system and rewarded you with some Telerik points.

You can follow the status of the issue in our Feedback Portal.

A possible solution I can offer is to use Data Annotations. You can use the regular expression "^[1-9][0-9]*$" for any positive integer, excluding zero.

Regards,
Dilyan Traykov
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Cory
Top achievements
Rank 1
Answers by
Cory
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or