Skip to main content

Notifications

Announcements

No record found.

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

  • Greg's Mom Profile Picture
    Greg's Mom 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.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 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
    Greg's Mom 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?  

  • Hossein.K Profile Picture
    Hossein.K 6,642 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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,820 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans