web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Autosize grid fields to contents

(0) ShareShare
ReportReport
Posted on by

Hello all,

Is it possible to size grid columns to the text through code?  If I open my grid some of the columns are too wide and contain extra white space while other fields are too small and the numbers in those cells display like ####.  If I double click on the right edge of the column header, the cell resizes to perfectly fit my data.  Is it possible to automate this so that the form opens with the width of each column fitting the data?  Looking at the FormControl.width and widthMode methods, I see I can specify the specific width and width mode (Exact, Auto, or Column Width).  None of those seem to resize the column like double clicking the right edge of the header.  Does anyone know how to do this? 

*This post is locked for comments

I have the same question (0)
  • Hossein.K Profile Picture
    6,648 on at
    RE: Autosize grid fields to contents

    Hi Brawndo,

    Change the width property of the Grids to whatever value that suits your needs.

    Check link below for find other properties:

    https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/user-interface/sizing-input-controls-grid-columns

  • Greg's Mom Profile Picture
    on at
    RE: Autosize grid fields to contents

    Thanks for the suggestion, Hossein.  I should have mentioned explicitly that I'm using AX 2012 R2.  It looks like the link you provided is for D365.  I have tried width mode Auto and Column Width on the grid fields as well as the autoSizeColumns method on the grid but none work to auto size the columns to the content of the cell.  Does anyone have any suggestion to automate the auto-sizing of columns in a grid?  

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Autosize grid fields to contents

    Maybe there is a method that the double click triggers, and which you could call from your code to avoid manual clicking. I don't have a system at hand right now so I can't check myself. But I would try to find it from the overridable methods of the form control.

    However you might have a grid with 10 000 records, and only one screenful is shown. I think it's not possible for the system to know the length of the longest value in those 10 000 records (without performance cost) so the field can never be perfectly sized.

    To my understanding the system will draw the grid before executing the query, so I don't know where you should place your double click caller, even if you manage toto implement it. Maybe to the end of the executeQuery method. Then the fields would change size after each executed query, making the UI quite jumpy.

  • Greg's Mom Profile Picture
    on at
    RE: Autosize grid fields to contents

    You make some great points, Nikolaos.  I'll see if I can capture that event and if so, find out how jumpy it makes the UI.  I think you're right it will need to happen after the execute query method.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#1
Community Member Profile Picture

Community Member 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans