Dynamically change the width of Datagrid column in FLEX

user120118 picture user120118 · Jun 16, 2009 · Viewed 16.1k times · Source

Can we change the width of the datagrid column dynamically by clicking on the border of the column in order to display the complete string which is too long to be displayed and needs to be scrolled ? If so, How ?

Also, how can we ensure that the column width changes dynamically based on the number of characters / length of string; since many a times the data is too long to be displayed. Can we set the column width to take the length of data into consideration before displaying onto the datagrid ?

Answer

Rob Lund picture Rob Lund · Nov 23, 2009

So I was having a similar problem and here is what I found. If you set:

horizontalScrollPolicy="off"

Then the column widths will size automatically to fit the width of the DataGrid. You can also manually set the column widths, as long as scrolling is set to either on or off and not set to auto. I found an interesting article about this, http://junleashed.wordpress.com/2008/07/10/flex-datagridcolumn-width-management/. Basically, he manages the column widths manually, and then calculates whether the scrollbar should be on or off.