Completed
Last Updated: 05 Apr 2023 10:02 by ADMIN
Release R1 2023 SP1
Martin
Created on: 08 Oct 2022 12:12
Category: UI for WinForms
Type: Feature Request
1
RadGridView: GridViewTemplate.SetError does not communicate back the Cancel-property

This is about this method:

        public void SetError(GridViewCellCancelEventArgs e, Exception exception)
        {
            GridViewDataErrorEventArgs args = new GridViewDataErrorEventArgs(exception, 0, 0, GridViewDataErrorContexts.Commit);
            if (e != null)
            {
                args = new GridViewDataErrorEventArgs(exception, e.ColumnIndex, e.RowIndex, GridViewDataErrorContexts.Commit);
            }
            this.EventDispatcher.RaiseEvent<GridViewDataErrorEventArgs>(EventDispatcher.DataError, this, args);

            if (args.ThrowException)
            {
                throw args.Exception;
            }

            if (args.Cancel)
            {
                //TODO: cancel row edit 
            }
        }

The method GridViewTemplate.SetError accepts a parameter of type GridViewCellCancelEventArgs (named e), but uses the information to create a new object of type GridViewDataErrorEventArgs (named args) and uses information from e to fill args.

The method then fires an event with args. Args also has a property Cancel which can be set in the event handlers. But nothing is done with that property.

Parameter e also has a property Cancel which is never be filled. So it could be useful, at the end of SetError, to set e.Cancel with args.Cancel. This way the caller can use the Cancel information from the events.

This request is also related to my next request. 

PS: Why is GridViewCellCancelEventArgs  called this way? It implies it has arguments for an event, but it is not used for an event, am I right?

3 comments
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 08 Dec 2022 11:47

Hi, Martin,

The provided feedback is greatly appreciated. I have approved this feature request so the SetError method would offer a more suitable approach for data validation in RadGridView.

Make sure that you cast your vote for the item in order to increase its priority. You can follow the item in order to get notified once any status changes occur.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Martin
Posted on: 07 Dec 2022 14:15

SetError is a public method and can be used by a developer. It fires the even DataError. The DataError event can ben handled by that same programmer. The fact that Telerik does not use the eventargs Cancel-property, does not mean that the programmer doesn't want to use it either. 

I am interested, as a programmer, when calling SetError in the fact that a the DataError handler has tried to cancel something. As you said: It is not used (by Telerik), then why not use it for something else?

 

ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 12 Oct 2022 13:20
Hello, Martin,  

RadGridView offers the DataError event which fires when an error on the DataSource side occurs, e.g. ConstraintException. It is not expected to keep the editor opened while a valid value is entered. This event offers GridViewDataErrorEventArgs which is a derivative of CancelEventArgs from where the Cancel argument is inherited. However, the Cancel argument is not used in this case. It is just enough to subscribe to the DataError event and the constraint error message (or another data error) wouldn't be shown to the end user. If you decide to notify the user for the incorrect data, you can show a message: 
       private void radGridView1_DataError(object sender, GridViewDataErrorEventArgs e)
        {
            RadMessageBox.Show(e.Exception.Message); 
        }

It would be greatly appreciated if you can provide more details about the use case that you want to cover. Thus, we will get better understanding of the precise case and provide further assistance. Thank you in advance.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.