Completed
Last Updated: 01 Nov 2022 13:06 by ADMIN
Release R3 2022 SP2
Martin
Created on: 08 Oct 2022 12:23
Category: UI for WinForms
Type: Feature Request
0
RadGridView: New overload for GridViewTemplate.SetError.

This is about the following 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 
            }
        }

Right now, the method GridViewTemplate.SetError accepts a parameter of type GridViewCellCancelEventArgs, which in itself is weird, because event args should only be used inside events and OnXXX-methods. But since SetError fires an event, one could argue that this method is like a OnXXX-method.

But inside it becomes more weird, it translates GridViewCellCancelEventArgs into GridViewDataErrorEventArgs. And I must admit, the last DataError-args feel a lot more logical that CellCancel-args when firing setting an error. Furthermore, if I create an override of class GridViewCellCancelEventArgs to contain more data about an error, this information never reaches the event handlers.

So why this translation? Or better: Why this parameter?

My suggestion would be to make a new overload:


public void SetError(GridViewDataErrorEventArgs e)
{
    if (e == null)
        throw new ArgumentNullException(nameof(e));

        this.EventDispatcher.RaiseEvent<GridViewDataErrorEventArgs>(EventDispatcher.DataError, this, args);

        if (args.ThrowException)
                throw args.Exception;

        if (args.Cancel)
        {
                // TODO: I really do not know what telerik wanted to do here, so I live this up to Telerik.
        }
}
Furthermore you could consider markering the other SetError-methods as obsolete.
1 comment
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 14 Oct 2022 10:00

Hi, Martin,

I have approved this request for improving the SetError method.

I have also updated your Telerik points.

It would be good to share further details about the exact usage of the SetError method in your application. Thus, we would get better understanding of the precise case and suggest an alternative approach if such one exists.

Thank you in advance for your cooperation.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.