views:

269

answers:

2

HI, In flex, I have a datagrid with 22 columns. I initially display all the columns. The width of each column right is uniform. Now when i change the visiblity of a few columns, the width of each column varies. How do i maintain a uniform column width for each column whether or not there are any invisible columns?... Also how do i get the count of number of visible columns. the ColumnCount property returns total number of columns and not the number of visible ones.

A: 

The columns are an array, so you can append code to whatever function makes them invisible and loop through that array setting each ones width. You will just need to keep tabs on your Datagrids width, and the number of visible columns, which you can also do with a loop. Here's some untested code that should put you close to your goal:

function makeAColInvisible():void{ //code you use to set col invisible

var visColCount:number = 0; for each (var item:DataGridColumn in myDataGrid.columns){ if(item.visible == true){ visColCount++; } }

for each (var item2:DataGridColumn in myDataGrid.columns){ item2.width = myDataGrid.width / visColCount; } }

invertedSpear
A: 

I tried your suggestion and it worked to some extent as in, it set the width for the first few columns correctly but then the last few columns became either extremely small or large. i placed alerts to see the width of each column and it was correct for the first few. my datagrid width is 100% so i'm using the width of the container(canvas) to calculate the width of each column so that cant be the problem. Any ideas?.

Ra