We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SfDataGrid column width AutoWithLastColumnFill to specific column

Hello, I'm using the SfDataGrid and i want the SfDataGrid to fill the width of the window whenever I'm resizing the window. I'm using the ColumnSizer="AutoWithLastColumnFill"  to do that, but I want a specific column to have that ability and not the last one. In my case is the second column (In other words, when I'm resizing the window i want the second column width to change). I tried setting the SfDataGrid.ColumnSizer="Auto" and the column i want to ColumnSizer="AutoWithLastColumnFill" but it does not work.  Any help?

Thanks

George



3 Replies

GS George Sterg September 25, 2015 05:45 PM UTC

I' made a workaround and I'm sharing it:
 Used a MultiBinding Converter and added the Window Width and the rest of the columns ActualWidth as parameters

 <syncfusion:GridTextColumn.Width>
                            <MultiBinding Converter="{StaticResource AutoFillColumnWidthConverter}">
                                <Binding Path="Width" ElementName="Window"  FallbackValue="0"/>
                                <Binding Path="ActualWidth" ElementName="Column1" FallbackValue="0"/>
                                <Binding Path="ActualWidth" ElementName="Column3" FallbackValue="0"/>
                                <Binding Path="ActualWidth" ElementName="Column4" FallbackValue="0"/>
                                <Binding Path="ActualWidth" ElementName="LastColumn" FallbackValue="0"/>
                            </MultiBinding>
                        </syncfusion:GridTextColumn.Width>


 public class AutoFillColumnWidthConverter : IMultiValueConverter
    {
        public double WindowWidth { get; set; }
    

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            WindowWidth = (double)values[0];


            double DataGridWidth = 0;
            List<object> list = values.ToList();
            list.RemoveAt(0);

            foreach (var value in list)
            {
                double width = System.Convert.ToDouble(value);
                if (!double.IsNaN(width))
                {
                    DataGridWidth += width;
                }
            }
            return WindowWidth  - DataGridWidth;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }




JG Jai Ganesh S Syncfusion Team September 28, 2015 12:51 PM UTC

Hi George,


Thank you for using Syncfusion Products.


We have analyzed your query. We cannot achieve your requirement directly to adjust the specific column width like AutoWithLastColumnFill behavior for last column. Currently we are working on the sample to achieve your requirement by overriding the GridColumnSizer and we will let you know the status on or before September 30, 2015.


Please let us know if you have any query.


Thank you,

Jai Ganesh S



JG Jai Ganesh S Syncfusion Team October 1, 2015 02:32 AM UTC

Hi George,


You can achieve your requirement to “Adjust the specific column width like AutoWithLastColumnFill behavior for last column” through work around. We have prepared the sample based on this and you can download the sample from the below location,


Sample: http://www.syncfusion.com/downloads/support/directtrac/144750/ze/SfGridDemo-346634687


In the above sample, we have adjusted the width for EmployeeArea column.


Please let us know if you have any other query.


Regards,

Jai Ganesh S


Loader.
Up arrow icon