RE: [flexcoders] Re: Setting DataGridColumn width programmatically & visibleColumns
I would try copying every DataGridColumn in the columns array to make a completely new array of new DGC instances then set the columns property. var oldCols:Array = dg.columns; var n:int = oldCols.length; var newCols:Array = new Array(); for (var i:int = 0; i < n; i++_ { var col:DataGridColumn = new DataGridColumn(); col.dataField = oldCols[i].dataField; col.headerText = oldCols[i].headerText; ... col.width = newlyCalculatedWidth; newCols.push(cols); } dg.cols = newCols; From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of ben.clinkinbeard Sent: Thursday, April 19, 2007 11:34 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Setting DataGridColumn width programmatically & visibleColumns Sorry if I am being really dense but I take it you can't just check the "visible" property of the column? Ben --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "parkerwhirlow" <[EMAIL PROTECTED]> wrote: > > So, I'm finding that this is really a nasty bug, and I haven't found a > good work-around. > > I've tried searching through the DataGrid.columnMap to ensure there's > renderers for my column before setting the width. This works until you > scroll horizontally. The columns that used to be visible, but aren't > anymore still have renderers in columnMap... and as soon as you set > the width on a non-visible column, bam... null reference error. > > I've submitted a bug report on Flex 2.0.1 through the normal feedback > channel. > > Still looking for some kind of work-around if anyone knows of one, I > really need something! > > thanks, > PW > > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "parkerwhirlow" > wrote: > > > > Hi, > > > > I have an issue where I've created a special routine to calculate the > > size of the columns in my DataGrid subclass. > > > > The problem I have is that I have several data grids that interact > > with eachother, and not all columns are visible (or were ever visible). > > > > When I programmatically set the width of the columns, if the columns > > have not been shown (are not in the 'visibleColumns' array) I get a > > null pointer error. See the stack trace below. > > > > Since I can't get to the 'visibleColumns' collection, how can I set > > the 'desired' widths of my columns without running into this error? > > > > Also, looking at the actual code, they tried to check for some timing > > on whether they had calc'd columns. But they don't check if the column > > you're setting the width on is in the 'visibleColumns' list. This > > seems like a relatively simple defect to fix... It should fall into > > that upper if block, and set the width on the column itself, right? > > > > > > thanks, > > Parker Whirlow > > __ > > > > TypeError: Error #1010: A term is undefined and has no properties. > > at > > > mx.controls::DataGrid/http://www.adobe.com/2006/flex/mx/internal::resize Column <http://www.adobe.com/2006/flex/mx/internal::resizeColumn> ()[C:\dev\flex_201_gmc\sdk\frameworks\mx\controls\DataGrid.as:2462] > > at mx.controls.dataGridClasses::DataGridColumn/set > > > width()[C:\dev\flex_201_gmc\sdk\frameworks\mx\controls\dataGridClasses\D ataGridColumn.as:1048] > > at > > > company.visualizations::MyGrid/company.visualizations:MyGrid::setDefault ColumnWidths()[C:\work\Flex\src\company\visualizations\MyGrid.as:1720] > > > > _ > > source at DataGrid:2462 > > > > // there's a window of time before we calc columnsizes > > // that someone can set width in AS > > if (!visibleColumns || visibleColumns.length == 0) > > { > > columns[col].setWidth(w); > > return; > > } > > > > if (w < visibleColumns[col].minWidth) // ERROR IS HERE > > w = visibleColumns[col].minWidth; > > >
[flexcoders] Re: Setting DataGridColumn width programmatically & visibleColumns
Ben, No problem. I appreciate the thought and the response. The column's 'visible' property only states whether the column should be shown, not whether it is currently visible on the screen (I.E. a column that is scrolled off the edge of the data grid is not visible even though it's 'visible' property is true) I believe the column's visible property relates to the DataGrid's private list 'displayableColumns' /** * @private * Columns with visible="true" */ private var displayableColumns:Array; and the DataGrid's 'visibleColumns' list are ones that are actually visible to the user. Anyway, I think I have a relatively OK workaround for now, I just put a try/catch block around the call, and ignore any errors... its working so far. =) thanks, PW --- In flexcoders@yahoogroups.com, "ben.clinkinbeard" <[EMAIL PROTECTED]> wrote: > > Sorry if I am being really dense but I take it you can't just check > the "visible" property of the column? > > Ben > > > --- In flexcoders@yahoogroups.com, "parkerwhirlow" > wrote: > > > > So, I'm finding that this is really a nasty bug, and I haven't found a > > good work-around. > > > > I've tried searching through the DataGrid.columnMap to ensure there's > > renderers for my column before setting the width. This works until you > > scroll horizontally. The columns that used to be visible, but aren't > > anymore still have renderers in columnMap... and as soon as you set > > the width on a non-visible column, bam... null reference error. > > > > I've submitted a bug report on Flex 2.0.1 through the normal feedback > > channel. > > > > Still looking for some kind of work-around if anyone knows of one, I > > really need something! > > > > thanks, > > PW > > > > --- In flexcoders@yahoogroups.com, "parkerwhirlow" > > wrote: > > > > > > Hi, > > > > > > I have an issue where I've created a special routine to calculate the > > > size of the columns in my DataGrid subclass. > > > > > > The problem I have is that I have several data grids that interact > > > with eachother, and not all columns are visible (or were ever > visible). > > > > > > When I programmatically set the width of the columns, if the columns > > > have not been shown (are not in the 'visibleColumns' array) I get a > > > null pointer error. See the stack trace below. > > > > > > Since I can't get to the 'visibleColumns' collection, how can I set > > > the 'desired' widths of my columns without running into this error? > > > > > > Also, looking at the actual code, they tried to check for some timing > > > on whether they had calc'd columns. But they don't check if the column > > > you're setting the width on is in the 'visibleColumns' list. This > > > seems like a relatively simple defect to fix... It should fall into > > > that upper if block, and set the width on the column itself, right? > > > > > > > > > thanks, > > > Parker Whirlow > > > __ > > > > > > TypeError: Error #1010: A term is undefined and has no properties. > > > at > > > > > > mx.controls::DataGrid/http://www.adobe.com/2006/flex/mx/internal::resizeColumn()[C:\dev\flex_201_gmc\sdk\frameworks\mx\controls\DataGrid.as:2462] > > > at mx.controls.dataGridClasses::DataGridColumn/set > > > > > > width()[C:\dev\flex_201_gmc\sdk\frameworks\mx\controls\dataGridClasses\DataGridColumn.as:1048] > > > at > > > > > > company.visualizations::MyGrid/company.visualizations:MyGrid::setDefaultColumnWidths()[C:\work\Flex\src\company\visualizations\MyGrid.as:1720] > > > > > > _ > > > source at DataGrid:2462 > > > > > > // there's a window of time before we calc columnsizes > > > // that someone can set width in AS > > > if (!visibleColumns || visibleColumns.length == 0) > > > { > > > columns[col].setWidth(w); > > > return; > > > } > > > > > > if (w < visibleColumns[col].minWidth) // ERROR IS HERE > > > w = visibleColumns[col].minWidth; > > > > > >
[flexcoders] Re: Setting DataGridColumn width programmatically & visibleColumns
Sorry if I am being really dense but I take it you can't just check the "visible" property of the column? Ben --- In flexcoders@yahoogroups.com, "parkerwhirlow" <[EMAIL PROTECTED]> wrote: > > So, I'm finding that this is really a nasty bug, and I haven't found a > good work-around. > > I've tried searching through the DataGrid.columnMap to ensure there's > renderers for my column before setting the width. This works until you > scroll horizontally. The columns that used to be visible, but aren't > anymore still have renderers in columnMap... and as soon as you set > the width on a non-visible column, bam... null reference error. > > I've submitted a bug report on Flex 2.0.1 through the normal feedback > channel. > > Still looking for some kind of work-around if anyone knows of one, I > really need something! > > thanks, > PW > > --- In flexcoders@yahoogroups.com, "parkerwhirlow" > wrote: > > > > Hi, > > > > I have an issue where I've created a special routine to calculate the > > size of the columns in my DataGrid subclass. > > > > The problem I have is that I have several data grids that interact > > with eachother, and not all columns are visible (or were ever visible). > > > > When I programmatically set the width of the columns, if the columns > > have not been shown (are not in the 'visibleColumns' array) I get a > > null pointer error. See the stack trace below. > > > > Since I can't get to the 'visibleColumns' collection, how can I set > > the 'desired' widths of my columns without running into this error? > > > > Also, looking at the actual code, they tried to check for some timing > > on whether they had calc'd columns. But they don't check if the column > > you're setting the width on is in the 'visibleColumns' list. This > > seems like a relatively simple defect to fix... It should fall into > > that upper if block, and set the width on the column itself, right? > > > > > > thanks, > > Parker Whirlow > > __ > > > > TypeError: Error #1010: A term is undefined and has no properties. > > at > > > mx.controls::DataGrid/http://www.adobe.com/2006/flex/mx/internal::resizeColumn()[C:\dev\flex_201_gmc\sdk\frameworks\mx\controls\DataGrid.as:2462] > > at mx.controls.dataGridClasses::DataGridColumn/set > > > width()[C:\dev\flex_201_gmc\sdk\frameworks\mx\controls\dataGridClasses\DataGridColumn.as:1048] > > at > > > company.visualizations::MyGrid/company.visualizations:MyGrid::setDefaultColumnWidths()[C:\work\Flex\src\company\visualizations\MyGrid.as:1720] > > > > _ > > source at DataGrid:2462 > > > > // there's a window of time before we calc columnsizes > > // that someone can set width in AS > > if (!visibleColumns || visibleColumns.length == 0) > > { > > columns[col].setWidth(w); > > return; > > } > > > > if (w < visibleColumns[col].minWidth) // ERROR IS HERE > > w = visibleColumns[col].minWidth; > > >
[flexcoders] Re: Setting DataGridColumn width programmatically & visibleColumns
So, I'm finding that this is really a nasty bug, and I haven't found a good work-around. I've tried searching through the DataGrid.columnMap to ensure there's renderers for my column before setting the width. This works until you scroll horizontally. The columns that used to be visible, but aren't anymore still have renderers in columnMap... and as soon as you set the width on a non-visible column, bam... null reference error. I've submitted a bug report on Flex 2.0.1 through the normal feedback channel. Still looking for some kind of work-around if anyone knows of one, I really need something! thanks, PW --- In flexcoders@yahoogroups.com, "parkerwhirlow" <[EMAIL PROTECTED]> wrote: > > Hi, > > I have an issue where I've created a special routine to calculate the > size of the columns in my DataGrid subclass. > > The problem I have is that I have several data grids that interact > with eachother, and not all columns are visible (or were ever visible). > > When I programmatically set the width of the columns, if the columns > have not been shown (are not in the 'visibleColumns' array) I get a > null pointer error. See the stack trace below. > > Since I can't get to the 'visibleColumns' collection, how can I set > the 'desired' widths of my columns without running into this error? > > Also, looking at the actual code, they tried to check for some timing > on whether they had calc'd columns. But they don't check if the column > you're setting the width on is in the 'visibleColumns' list. This > seems like a relatively simple defect to fix... It should fall into > that upper if block, and set the width on the column itself, right? > > > thanks, > Parker Whirlow > __ > > TypeError: Error #1010: A term is undefined and has no properties. > at > mx.controls::DataGrid/http://www.adobe.com/2006/flex/mx/internal::resizeColumn()[C:\dev\flex_201_gmc\sdk\frameworks\mx\controls\DataGrid.as:2462] > at mx.controls.dataGridClasses::DataGridColumn/set > width()[C:\dev\flex_201_gmc\sdk\frameworks\mx\controls\dataGridClasses\DataGridColumn.as:1048] > at > company.visualizations::MyGrid/company.visualizations:MyGrid::setDefaultColumnWidths()[C:\work\Flex\src\company\visualizations\MyGrid.as:1720] > > _ > source at DataGrid:2462 > > // there's a window of time before we calc columnsizes > // that someone can set width in AS > if (!visibleColumns || visibleColumns.length == 0) > { > columns[col].setWidth(w); > return; > } > > if (w < visibleColumns[col].minWidth) // ERROR IS HERE > w = visibleColumns[col].minWidth; >