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

How to show Validation Error Message on GridView level

1 Answer 172 Views
GridView
This is a migrated thread and some comments may be shown as answers.
NayLin
Top achievements
Rank 1
NayLin asked on 17 Mar 2016, 09:10 AM

I have learned that RadGridView has data validation feature per cell and row. But in my case, I want data validation on GridView level. In my app, I have "Purchase Order Form". In this form, there is RadGridView for Purchase Order Items. The validation scenario is User must add at least one item to this RadGridView.

I use the way of Data Annotation and Validation Attribute in my ViewModel to check this validation.

[CollectionHasElements( ErrorMessage = "Purchase order must have at least one order item." )]
        public ObservableCollection<PurchaseOrderItemDecorator> PurchaseOrderItemDecorators
        {
            get { return _purchaseOrderItemDecorator; }
            set { SetProperty( ref _purchaseOrderItemDecorator, value ); }
        }

The RadGridView successfully notify the error by showing Red Border around the grid. But it somehow failed to show the error message. I attached the screenshot of this RadGridView.

In normal telerik wpf controls, it usually shows the error message on top right corner red block triangle. I wish my Gridview act like that for showing validation error message.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 21 Mar 2016, 12:28 PM
Hello NayLin,

I tried achieving such behavior of the control when validating it through a ValidationAttribute, but to no avail. RadGridView performs its validation on row level, which is the expected behavior. You can check out the attached demo application as a demonstration.

As to achieving the desired result, a possible solution might be to subscribe to the CellValidating event and within the event handler set the BorderBrush of the control to "Red".  Then, you can define a property in the view model to which the ToolTip showing the error message will be bound. In order to position the ToolTip in the top right corner of RadGridView, I suggest you taking a look at this and this StackOverflow threads. You may also find this MSDN article useful on the matter.

Regards,
Stefan X1
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
NayLin
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or