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

GridViewDataColumn autoresizing

6 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jiri
Top achievements
Rank 1
Jiri asked on 18 Nov 2016, 08:52 PM

I am facing problem with column width autoresizing.

I have code like that bellow.

 <RadGridView ItemsSource="{Binding SomeObservableCollection}">

    …

  <RadGridView.Columns>
   <GridViewDataColumn Header="First" DataMemberBinding="{Binding NameSource}" MinWidth="60"/>
   <GridViewDataColumn Header="Second" DataMemberBinding="{Binding ValueSource}" MinWidth="145"/>
  </RadGridView.Columns>

</RadGridView>

Columns auto resizing work well but only in one way. One time the width is increased never until new app start is decreased. I want width fit to content on each column all the time but never be thinner then MinWidth property value.

I have search very much but I have found no solution. For WPF there is not Autoresizing behaviour or Autoresize or BestFit method. Even if I set the Width property programmatically the ActualWidth property value never changes. I definitely call UpdateLayout on RadGridView.

Is there some simple solution?

Thank you very much.

6 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 23 Nov 2016, 01:03 PM

Hi Jiri,

Can you try setting RadGridView's ColumnWidth property to SizeToCells and let me know about the result?

Regards,

Yoan
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
0
Jiri
Top achievements
Rank 1
answered on 25 Nov 2016, 03:19 PM

Hi Yoan,

I have tried it also before asking. In this case takes no visual effect because MinWidth is always longer than header text of both columns.

 

0
Yoan
Telerik team
answered on 30 Nov 2016, 12:37 PM
Hello Jiri,

I am not sure that I can understand the exact problem. May I ask you to check the attached sample project and let me know how it differs from your requirement? Please notice that the MinWidth of the column is longer than the header and the SizeToCells property takes effect.

Regards,
Yoan
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
0
Jiri
Top achievements
Rank 1
answered on 09 Dec 2016, 05:51 PM
I see no grid even If I uncomment related code.
0
Yoan
Telerik team
answered on 14 Dec 2016, 04:49 PM
Hi,

Are you using NoXAML binaries? Please note that if you are using them and if there is a style targeting RadGridView, you will need to use the BasedOn attribute as demonstrated in the "Basing a Custom Style on a Theme Default Style" section of this help article.

Regards,
Yoan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
보규
Top achievements
Rank 1
answered on 08 Jul 2018, 05:37 AM

I have same problem (One time the width is increased never until new app start is decreased.)
I tried the header column assigned with new GridViewLength() but never changed column with
So, i used some fake as follows

public class ExtRadGridView : RadGridView
{
 public void BestFitColumns()
 {
  this.ChildrenOfType<GridViewHeaderCell>()
   .Where(f=>f.Column != null)
   .Where(f=>f.Column.Width.IsAuto)
   .ToList()
   .ForEach(f =>
  {
   var thumb = f.ChildrenOfType<System.Windows.Controls.Primitives.Thumb>().LastOrDefault();
   if (thumb != null)
   {
    f.Column.Width = 10;
    f.Column.Width = new GridViewLength(1, GridViewLengthUnitType.Auto, 1, 1);
    var args = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
    {
     RoutedEvent = Control.MouseDoubleClickEvent
    };
    thumb.RaiseEvent(args);
   }
  });
 }
}
See GridViewHeaderCell Template
I hope it helps.

Tags
GridView
Asked by
Jiri
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Jiri
Top achievements
Rank 1
보규
Top achievements
Rank 1
Share this question
or