Always Fill?

I am using an SfDataGrid in a UWP application.  I would like the grid always to fill, horizontally, a cell in a parent grid (not a data grid - just a Windows grid).  I have five columns, which can all be the same width.  (I'd prefer to set the widths proportionally using something like "*", "2*", etc., but that's less important.)  I would like to set a minimum width on the grid columns and, if the space is too narrow a scroll bar would appear and if it's too wide the columns stretch to fill the space.  Despite my many attempts and many combinations/permutations, I have been unable to make this happen.  Help would be much appreciated.

Thanks!
Brad.

2 Replies

AR Antony Raj M Syncfusion Team September 5, 2016 10:24 AM UTC

Hi Bradley, 

We have analyzed your query and you can achieve your requirement by overriding the Refresh method in GridColumnSizer like below code example. 

 
public MainPage() 
{ 
    this.InitializeComponent(); 
    this.dataGrid.GridColumnSizer = new GridColumnSizerExt(this.dataGrid); 
} 
 
 
public class GridColumnSizerExt:GridColumnSizer 
{ 
    public GridColumnSizerExt(SfDataGrid dataGrid) : base(dataGrid) { } 
 
    protected override void Refresh(double AvailableWidth) 
    { 
        base.Refresh(AvailableWidth); 
        var visualContainer = this.DataGrid.GetVisualContainer(); 
        if(AvailableWidth > visualContainer.ScrollColumns.ViewSize) 
        { 
            DataGrid.ColumnSizer = GridLengthUnitType.Star; 
            DataGrid.GridColumnSizer.Refresh(); 
        } 
    } 
} 

We also prepared the same and you can download the sample from below location. 

Sample: 

Please refer the below link to know more about column sizer. 

Regards, 
Antony Raj 



AR Antony Raj M Syncfusion Team September 5, 2016 10:28 AM UTC

Hi Bradley, 

You can download the sample for previous update from below link. 


Regards, 
Antony Raj 


Loader.
Up arrow icon