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

ColumnWidthChanged vs ColumnWidthChanging

3 Answers 258 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
Curtis asked on 02 Apr 2020, 09:37 PM

Hello!

I need to capture when column-resizing with a mouse has COMPLETED.  I expected this would be done in ColumnWidthChanged but for reasons unknown to me that event fires WHILE the user is resizing...exactly like how I would expect ColumnWidthChanging  to work.

 

It's like the resize is happening "Live" instead of waiting for the user to complete their resize THEN firing. 

Any suggestions would be very much appreciated!

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Apr 2020, 12:38 PM
Hello, Curtis,  

The ColumnWidthChanged event is expected to be fired when the width of a column is changed. When the resize cursor is shown and you move the mouse, this adjusts the width accordingly while the resize operation is still ongoing. The column's width is indeed affected. That is why the ColumnWidthChanged event is fired. The ColumnWidthChanging event on the other hand is expected to be fired in a similar situation just before the width property is changed since it allows cancelling the change operation.

In order to detect when the resize operation is completed, it is possible to handle the RadGridView.MouseUp event, check the RadGridView.Cursor and the element under the mouse: 
        private void radGridView1_MouseUp(object sender, MouseEventArgs e)
        {
            if (this.radGridView1.Cursor == Cursors.SizeWE)
            {
                GridHeaderCellElement headerCell = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridHeaderCellElement;
                if (headerCell != null)
                {
                    //TODO
                }
            }
        }
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 07 Apr 2020, 05:37 PM

It helps a great deal, thank you!  I'm afraid it makes no sense whatsoever though and that's a bit troubling.

The CHANGING event should be firing BEFORE AND DURING the change.   The CHANGED event should fire after the 'change' has occurred.   Asking your users to capture the mouse cursor in order to tell what happened to the grid...???  That's a little harsh IMO.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Apr 2020, 12:58 PM
Hello, Curtis,  

Thank you for providing your feedback. It is really appreciated.

I completely understand your point. It sounds more like that you need ColumnWidthChangeStart and ColumnWidthChangeEnd events which are not available in RadGridView out-of-the-box. 

However, we strive to follow some general approaches with the public API for the controls in the Telerik UI for WinForms suite. Usually, any x_Changing event is purposed to be fired when the certain property is about to be changed. This event should be cancel-able so the developer can determine whether the user can proceed further or not. If the x_Changing is not cancelled, the operation can proceed further and the x_Changed event is fired indicating that the property has already been changed. This logic is followed for the columns in RadGridView as well. 

We haven't had any complains about this API from other customers so far. However, if other customers find it inconvenient, we will definitely consider it in the future improvement of the control.

For now, feel free to use the previously suggested approach which I believe would fit your requirements.

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Al
Top achievements
Rank 1
commented on 28 Jan 2022, 12:53 AM

For what it is worth I completely agree with Curtis. Changed should be only after the event.  I find the mouse 'trick' just that; a trick and not logical. 
Dess | Tech Support Engineer, Principal
Telerik team
commented on 01 Feb 2022, 09:10 AM

Hello, Al,   

The provided feedback is greatly appreciated. The ColumnWidthChanged event is purposed to be fired when the width of a column is modified. Since the width changes are being applied dynamically while the user is moving the resize cursor, this event is fired multiple times. If the behavior was different and the column's width was adjusted only once after releasing the mouse, then the ColumnWidthChanged event would have been fired just once.

If other customers have similar requests we will consider extending the public API accordingly. Meanwhile, feel free to use the above suggested solution. 
 
Jeffrey
Top achievements
Rank 1
Veteran
Iron
Iron
commented on 13 Apr 2023, 08:44 PM

Hello

Just ran across this issue...and yes...I agree with Curtis.  It is unexpected for the event to be firing off continuously...during a move when the event states "CHANGED".

Anyway, thank you for the work around.

Jeff

Dess | Tech Support Engineer, Principal
Telerik team
commented on 14 Apr 2023, 04:20 AM

Hi, Jeffrey,

As the name ColumnWidthChanged speaks for itself, the event will be fired whenever there is a change in the column's width. That is why the event is fired while resizing the column. I believe that introducing new events, ColumnWidthChangeStart and ColumnWidthChangeEnd, would be a better option for detecting the moment of releasing the mouse after the resize operation. We will consider it in the future improvement of the control.

Tags
GridView
Asked by
Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or