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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Column autosize mode of AllCells is not working.

Thread ID:

Created:

Updated:

Platform:

Replies:

149420 Nov 25,2019 10:37 PM UTC Nov 26,2019 12:55 PM UTC WinForms 1
loading
Tags: SfDataGrid
Phunction
Asked On November 25, 2019 10:37 PM UTC

I am unable to get teh autosize to work with the columns if it is set to AllCells, it works fine if it is set to ColumnHeader

grid.AutoSizeColumnsMode = Syncfusion.WinForms.DataGrid.Enums.AutoSizeColumnsMode.AllCells;
...
grid.dt.Columns.Add(("Column1");
grid.dt.Columns.Add(("Column2");
grid.DataSource = grid.dt;  (dt is a DataTable)
...
DataRow dr = dt.Rows[1];
dr[1] = "short";
dr[2] = "really long text is truncated";


doing this after the above still makes no difference:
grid.AutoSizeColumnsMode = Syncfusion.WinForms.DataGrid.Enums.AutoSizeColumnsMode.AllCells;


Gowtham Gopalsamy [Syncfusion]
Replied On November 26, 2019 12:55 PM UTC

Hi Chris,  
    
Thanks for using Syncfusion controls.   
   
We have analyzed your provided code snippet and it’s working fine at our end. We have attached the tested sample for your reference. We suspect that you are adding the rows at runtime. You can achieve your requirement to fit the text in the cells at runtime by using AutoSizeController.ResetAutoSizeWidthForAllColumns method.     
   
Please find the below code snippet.  
   
DataTable employeeCollection = new DataTable();   
   
employeeCollection.Columns.Add("Column1"typeof(string));   
employeeCollection.Columns.Add("Column2"typeof(string));   
   
this.sfDataGrid.DataSource = employeeCollection;   
   
this.sfDataGrid.AutoSizeColumnsMode = AutoSizeColumnsMode.AllCells;   
   
private void button1_Click(object sender, EventArgs e)   
{   
    employeeCollection.Rows.Add("short""really long text is truncated");   
    employeeCollection.Rows.Add("short""really long text is truncated");   
    employeeCollection.Rows.Add("short""really long text is truncated");   
    employeeCollection.Rows.Add("short""really long text is truncated");   
   
    this.sfDataGrid.AutoSizeController.ResetAutoSizeWidthForAllColumns();   
    this.sfDataGrid.AutoSizeController.Refresh();   
   
}   
   
Please find the below sample link.   
    
   
Please refer the below UG link.  
   
   
Please let us know, if you require further assistance on this.   
    
Regards,   
Gowtham.   
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon