How to disable switching to auto GridView column width by double-clicking on GridViewHeaderCell.RightHeaderGripper

1 Answer 224 Views
GridView
Eduard
Top achievements
Rank 1
Eduard asked on 30 Aug 2022, 10:10 AM

Hi,

I`m looking for a way to disable the behavior when double-click on the separator between header cells of GridView sets column to adjust its width according to the widths of all currently visible items inside. For example WinForms DataGridView element has ColumnDividerDoubleClick event which allows me to override this behavior. I`m supposing that there should be something similar for GridView

Can you offer any advice?

Eduard

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 02 Sep 2022, 09:10 AM

Hello Eduard,

The RadGridView control does not expose an API that would allow you to prevent this behavior from occurring out-of-the-box. However, this could still be achieved by adding a new handler for the PreviewMouseDoubleClick event of the GridViewHeaderCell element. Then, in the new handler, if the e.OriginalSource is of the type Border, set the e.Handled property to True.

The following code snippet shows this suggestion's implementation:

this.AddHandler(GridViewHeaderCell.PreviewMouseDoubleClickEvent, new MouseButtonEventHandler(OnPreviewMouseDoubleClick));

private void OnPreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    if (e.OriginalSource is Border)
    {
        e.Handled = true;
    } 
}

The produced result is as follows:

Could you give this suggestion a try and let me know how it goes?

Regards,
Stenly
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.

Eduard
Top achievements
Rank 1
commented on 09 Sep 2022, 11:19 AM

Yup, that worked for me. Thanks a lot
Tags
GridView
Asked by
Eduard
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or