Just to follow up...

I installed hot fix 2 yesterday, which cleared up my problem with  
setting the width of non-visible columns (i.e. scrolled off to right  
in this case).

So, thank you jake247, your code is working very well for me.

Regards,

Ian
________________________________________
IMiJ Software
http://www.imijsoft.com
http://www.ianmjones.net (blog)


On 25 May 2007, at 19:08, Ian M. Jones wrote:

> Hi all,
>
> Thanks for the help Tracey and Tom, I've tried to do something along
> the lines of what you suggested but keep running up against the
> problem of casting from Object to DataGridColumn.
>
> jake247, your code works pretty well, I think I could probably alter
> it to get what I really want if I work on it a little more (the
> columns may need to be added or removed).
>
> However, I assume you're using a grid without a horizontal scroll
> bar, as I seem to have found a bug in the DataGrid when running your
> code. When it get's to the point where the width is set on the newCol
> for a column that is off to the right and not visible until the
> scrollbar is used, it complains about a missing property because it's
> internally trying to reference an element in the visibleColumns array
> which isn't there. I need to either fix this in the DataGrid source
> or find a work around.
>
> Ian
>
>
> On 24 May 2007, at 20:38, <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> wrote:
>
>> Ask and ye shall receive ... we solved this exact problem about a
>> month ago ...
>> --------------------------------------------------------------------- 
>> -
>> ---
>> //  Save grid settings to shared object
>>                      public function saveGridSettings():void {
>>                              var name:String = lineItemGrid.name;
>>                              var gWidth:int = lineItemGrid.width;
>>                              var cols:Array = new Array();
>>                              var savedLastSort:String = lastSort;
>>                              var savedReversed:Boolean = reversed;
>>                              for (var i:int = 0; i < 
>> lineItemGrid.columns.length; i++) {
>>                                      cols[i] = lineItemGrid.columns[i];      
>>                              }
>>                              
>>                              // Write grid data to shared object
>>                              lineItemGridSO = 
>> SharedObject.getLocal("gridData", "/");
>>                              lineItemGridSO.data.name = name;
>>                              lineItemGridSO.data.gridWidth = gWidth;
>>                              lineItemGridSO.data.lastSort = savedLastSort;
>>                              lineItemGridSO.data.reversed = savedReversed;
>>                              lineItemGridSO.data.gridCols = new Array();
>>                              lineItemGridSO.data.gridCols = cols;
>>                              lineItemGridSO.flush(); 
>>                      }
>>                      
>>                      // Get grid settings from shared object
>>                      public function getGridSettings():void {
>>                              lineItemGridSO = 
>> SharedObject.getLocal("gridData", "/");                
>>                              if (lineItemGridSO.data.name != undefined) {
>>                                      lastSort = 
>> lineItemGridSO.data.lastSort;        
>>                                      var newCols:Array = new Array();
>>                                      for (var i:int = 0; i < 
>> lineItemGridSO.data.gridCols.length; i+
>> +) {
>>                                              for (var j:int = 0; j < 
>> lineItemGrid.columns.length; j++) {
>>                                                      if 
>> (lineItemGrid.columns[j].dataField ==
>> lineItemGridSO.data.gridCols[i].dataField) {
>>                                                              var 
>> newCol:DataGridColumn = DataGridColumn
>> (lineItemGrid.columns.splice(int(j), 1)[0]);
>>                                                              newCol.width = 
>> lineItemGridSO.data.gridCols[i].width;
>>                                                              
>> newCols.push(newCol);
>>                                                      }
>>                                              }
>>                                      }
>>                                      newCols.concat(lineItemGrid.columns);
>>                                      lineItemGrid.columns = newCols;
>>                                                                      }
>>                      }
>> ---- "Ian M. Jones" <[EMAIL PROTECTED]> wrote:
>>> Hi all,
>>>
>>> I'm trying to set up a simple way to save a user's DataGrid column
>>> setup
>>> to a local SharedObject, and then retrieve those settings when
>>> they next
>>> run the application.
>>>
>>> Saving them seems to have been pretty simple:
>>>
>>> public function savePreferences():void {
>>>     var prefs:SharedObject = SharedObject.getLocal("Preferences");
>>>     var defaultColumns:Array = myDataGrid.columns;
>>>     prefs.data.defaultColumns = defaultColumns;
>>>     prefs.flush();
>>> }
>>>
>>> That works, I can see the objects in the Preferences.sol file, but I
>>> haven't found a way of setting the grid's columns after reading it
>>> back
>>> in.
>>>
>>> I've tried reading back into an array and then setting the columns
>>> property to the array.
>>> I've tried iterating through the array with a for each casting the
>>> results
>>> to a DataGridColumn, appending to an ArrayCollection and then  
>>> finally
>>> setting the DataGrid's columns to the ArrayCollection.toArray,
>>> that didn't
>>> get very far.
>>> I've tried binding the DataGrid's columns property to an Array,
>>> and then
>>> setting that array to the prefs.data.defaultColumns.
>>>
>>> Nothing seems to work, the app generally seems to hang at the
>>> point I try
>>> to set the columns property.
>>>
>>> Is there a kind soul that can point me in the right direction?
>>>
>>> Thanks,
>>> -- 
>>> Ian M. Jones
>>> ________________________________________
>>> IMiJ Software
>>> http://www.imijsoft.com
>>> http://www.ianmjones.net (blog)
>>>
>>
>>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders% 
> 40yahoogroups.com
> Yahoo! Groups Links
>
>
>
>

Reply via email to