I'm handling the ColumnWidthChanged event and saving the width of each column in a config file for reuse the next time my application is run. If I drag the column to a different size the NewWidth property is the actual width I've chosen. If I double-click the column edge to auto-size it, the NewWidth property is set to "Auto" and the value is "1".
Why can't I see what the actual new width is? My gut says this is counter-intuitive, but Telerik generally has a good reason for this sort of thing.
Any input as to how I can get the actual width so I can save it?
9 Answers, 1 is accepted
You can check this forum thread where this question had already been discussed.
Regards,
Yoan
Progress Telerik
Hey Yoan,
I tried what the other forum post suggested and it's still not working.
Can you confirm that the following code needs to be placed within the ColumnWidthChanged event handler? If so, when I step through the method that is being invoked, e.Column.ActualWidth is always equal to "2".
if
(e.NewWidth.IsAuto)
{
this
.radGridView.Dispatcher.BeginInvoke((Action)(()=>YourMethodHere(e.Column.ActualWidth)));
}
Yes, you can use the ColumnWidthChanged event. I have tested this in a sample project and it works as expected. Can you confirm how it works at your side?
Regards,
Yoan
Progress Telerik
Sorry to spam this topic. I managed to get your sample project to reproduce the issue by doing the following:
In the MainWindow.xaml.cs file, change a column width in the constructor after InitializeComponent() is called. My constructor looks like this:
public
MainWindow()
{
InitializeComponent();
clubsGrid.Columns[ 2 ].Width = 130;
}
When you double click the column header to get the width, the value returned by the ActualWidth property will be equal to the minimum column width (20 by default, I had mine set to 2).
You can try setting a priority of the Dispatcher like so:
this.clubsGrid.Dispatcher.BeginInvoke((Action)(() => Debug.WriteLine(e.Column.ActualWidth)),DispatcherPriority.Background);
It works in the sample project. Can you try it on your side?
Regards,
Yoan
Progress Telerik
It works!
Is there any chance you could tell me why the priority needed to be set to Background? I spent three days trying to figure this out. I'm curious what I missed.
It seems that this is a timing issue. Most probably the actual width of the column is not reevaluated when the ColumnWidthChanged is invoked. You can get it working by delaying the call to e.Column.ActualWidth. The easiest way to do that is to use a dispatcher with priority set.
Regards,
Yoan
Progress Telerik