How to show Validation Error Message on GridView level

2 posts, 0 answers
  1. NayLin
    NayLin avatar
    5 posts
    Member since:
    Feb 2016

    Posted 17 Mar Link to this post

    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.

  2. Stefan X1
    Admin
    Stefan X1 avatar
    521 posts

    Posted 21 Mar Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top