Auto sizing SfDataGrid columns Not Working as Expected

I have a simple program with several instances of SfDataGrid installed to show various lists of data to the user. In each control, I have set the ColumnSizer property to size my columns appropriately for each grid. However, the columns do not seem to be sized correctly in some of the grids.

Please look at these screenshots to see what I see in my results.

Image_1486_1710789962982

The grid on the left looks fine (ColumnSizer is set to AutoWithLastColumnFill here), but the grid on the right cuts off part of the first column's header. The complete text for this header is "Part Pins." ColumnSizer is set to Auto in this grid.

Image_3866_1710790108724

This grid also looks fine. ColumnSizer for this grid is set to AutoWithLastColumnFill. However, the following grid is set up identically, as seen here:


In this case, part of the text for the uppermost lefthand cell is cut off. The full text is "out[16]."

I don't know if I have done anything special to cause this behavior, so I wonder if anyone can help me resolve this issue.

Gil


5 Replies

SB Sweatha Bharathi Syncfusion Team March 19, 2024 02:10 PM UTC

Hi Gil Yoder ,



We have checked your requirement using the provided scenario. We utilized the Syncfusion TabControlExt to load the DataGrid within a TabItem. Then, we set the ColumnSizer to AutoWithLastColumnFill and Auto for the DataGrid and also configured the ColumnSizer property for the columns. In both cases, the ColumnSizer is working properly as expected in latest Syncfusion version(25.1.35).


Can you clarify how you set the ColumnSizer at runtime or during the initial loading, and how you define the ColumnSizer property for the grid or columns and mention in which Syncfusion version are you using?


We have provided a sample and an image for your reference. Kindly review the sample, and if possible, modify the provided sample to replicate your scenario.


This information will help us to proceed further.



UG Link : https://help.syncfusion.com/wpf/datagrid/autosize-columns


Attachment: Sample_and_Image_d9851c3a.zip


GY Gil Yoder March 19, 2024 03:40 PM UTC

Thank you for your response. I have looked at your attachments and don't see any real differences between your example and my code, except that I set the following within the UserControl tag where I have instances of SfDataGrid.

TextBlock.FontFamily="Courier New"

Please see my project attached to see if you can see an issue with my code.

Might the issue have anything to do with the fixed font size font I have employed?


Attachment: HdlSim_16a3e0f7.zip


SB Sweatha Bharathi Syncfusion Team March 20, 2024 02:20 PM UTC

Hi Gil Yoder ,


We have checked your reported scenario. You have set the FontFamily for the entire window. To avoid your reported scenario , you need to set the same font for the GridcolumnSizer. You can change the font settings for column width calculation by setting the GridColumnSizer.FontFamily, property. These settings will be considered for all columns.


We have provided sample for your reference. Kindly check and let us know if you have any further concerns on this.


Code Snippet:


  public partial class MainWindow : Window

  {

   

      public MainWindow()

      {

          InitializeComponent();

          this.autoWithLastColumnFillDataGrid.GridColumnSizer.FontFamily = new FontFamily("Courier New");

      }

 

 

 

  }



UG Link : https://help.syncfusion.com/wpf/datagrid/autosize-columns#changing-font-settings-for-datagrid


Attachment: SfDataGrid_Demo_595e1cad.zip


GY Gil Yoder March 20, 2024 02:47 PM UTC

Thank you! I can work with that.



JS Jayashree Suresh Anand Syncfusion Team March 21, 2024 09:54 AM UTC

Hi Gil,

You're welcome. Please let us know if you have any concerns, we will be happy to assist you. 

Regards,

Jayashree 


Loader.
Up arrow icon