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

Column resize event

2 Answers 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 14 Jan 2009, 10:43 PM
Hello,

Is there an event that is raised when a column is resized?  If not, do you have any suggestions about how to get notified whenever a column is resized?

Thanks,

Joel

2 Answers, 1 is accepted

Sort by
0
Accepted
Hristo Deshev
Telerik team
answered on 17 Jan 2009, 03:59 PM
Hello Joel,

We do not expose such an event at the moment. I found a relatively easy way to get notified when that happens. The header cells are placed in a Grid panel inside the header row. Each cell has a GridViewSplitter control beside it. A GridViewSplitter contains a Thumb control that we use for its DragDelta event. DragDelta is a bubbling event that you can handle on the RadGridView control:

<telerik:RadGridView Name="RadGridView1" Thumb.DragDelta="OnHeaderSplitterDrag"
</telerik:RadGridView> 

The hard part is getting the right cell and its column definition. Here is the code that does that:

private void OnHeaderSplitterDrag(object sender, DragDeltaEventArgs e) 
    var dragThumb = (DependencyObject) e.OriginalSource; 
    var headerSplitter = (UIElement) VisualTreeHelper.GetParent(dragThumb); 
    var headerRowGrid = (Grid) VisualTreeHelper.GetParent(headerSplitter); 
    var splitterIndex = headerRowGrid.Children.IndexOf(headerSplitter); 
    var cellColumnDefinitionIndex = (splitterIndex - 1) / 2; 
    var width = headerRowGrid.ColumnDefinitions[cellColumnDefinitionIndex].Width; 
 
    this.Title = "column resized to: " + width; 

I hope that does the job for you.

Best wishes,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
JP
Top achievements
Rank 1
answered on 19 Jan 2009, 04:30 PM
Hi Hristo,

This solution worked great, once I made a couple adjustments.  When I ran the code, the OriginalSource of the event was already a GridViewHeaderSplitter object, so I got rid of that line of code.  Also, the event seemed to get fired when the grid was scrolled too.  Below is the code I ended up with.

        private void OnHeaderSplitterDrag(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) 
        { 
            var headerSplitter = e.OriginalSource as GridViewHeaderSplitter; 
 
            if (headerSplitter != null
            { 
                var headerRowGrid = (Grid)VisualTreeHelper.GetParent(headerSplitter); 
                var splitterIndex = headerRowGrid.Children.IndexOf((UIElement)headerSplitter); 
                var cellColumnDefinitionIndex = (splitterIndex - 1) / 2; 
                var width = headerRowGrid.ColumnDefinitions[cellColumnDefinitionIndex].Width; 
 
                this.Title = "column resized to: " + width;  
            } 
        } 

Tags
GridView
Asked by
JP
Top achievements
Rank 1
Answers by
Hristo Deshev
Telerik team
JP
Top achievements
Rank 1
Share this question
or