Column autosize mode of AllCells is not working.
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
dr[2] = "really long text is truncated";
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";
doing this after the above still makes no difference:
grid.AutoSizeColumnsMode = Syncfusion.WinForms.DataGrid.Enums.AutoSizeColumnsMode.AllCells;
SIGN IN To post a reply.
3 Replies
GG
Gowtham Gopalsamy
Syncfusion Team
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.
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample_Demo190091927
Please refer the below UG link.
Please let us know, if you require further assistance on this.
Regards,
Gowtham.
RI
Richard
April 6, 2021 06:01 PM UTC
I can not get this to work with a BindingList dataset.
BindingList gridItems = new BindingList();
sfDataGrid.DataSource = gridItems;
sfDataGrid.AutoSizeColumnsMode = AutoSizeColumnsMode.AllCells;
sfDataGrid.Columns.Add(new GridTextColumn()
{
MappingName = "Item",
HeaderText = "Item Number"
});
sfDataGrid.Columns.Add(new GridTextColumn()
{
MappingName = "ItemDescription",
HeaderText = "Item Description"
});
//My master/detail navigation is the object that is setting gridItems, not me.
//I've tried the following workarounds - and I've confirmed that they all fire when the data changes, but it's not setting the size.
//This one had the most success, but it only seems to size to the first row of data
sfDataGrid.View.SourceCollectionChanged += (s, e) =>
{
sfDataGrid.AutoSizeController.ResetAutoSizeWidthForAllColumns();
sfDataGrid.AutoSizeController.Refresh();
}
//Tried this too - no change at all.
sfDataGrid.View.Records.CollectionChanged += (s, e) => { ... }
//Tried this also - no change
gridItems.ListChanged += (s, e) => { ... }
//Tried this as well - no change
sfdgItems.RowValidating += (s, e) => { ... }
MA
Mohanram Anbukkarasu
Syncfusion Team
April 7, 2021 12:34 PM UTC
Hi Richard,
Thanks for the update
We have prepared a sample using BindingList to refresh the AutoSizeController in SfDataGrid.View.Records.CollectionChanged event as shown in the following code example.
Code example :
|
this.sfDataGrid1.View.Records.CollectionChanged += Records_CollectionChanged;
private void Records_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (this.sfDataGrid1.View.Records.Count > 0)
{
sfDataGrid1.AutoSizeController.ResetAutoSizeWidthForAllColumns();
sfDataGrid1.AutoSizeController.Refresh();
}
}
|
Sample link : https://www.syncfusion.com/downloads/support/forum/149420/ze/SfDataGrid_BindingList1899843720
Please let us know if you require further assistance from us.
Regards,
Mohanram A.
SIGN IN To post a reply.
- 3 Replies
- 4 Participants
-
PH Phunction
- Nov 25, 2019 10:37 PM UTC
- Apr 7, 2021 12:34 PM UTC