0 Replies Latest reply on Apr 21, 2006 10:47 AM by exmedium

    DataGrid Inital selectedIndex Issue

    exmedium
      I'm having trouble setting the initial datagrid selectedIndex.

      I was initially trying to just set it manually to no avail.

      [CODE]
      grid.selectedIndex =0;

      /*or*/

      grid.setSelectedIndex(0);
      [/CODE]


      When I start the application the first time the selected index of the datagrid is not setting nor being retreived, however when I toggle between two functions
      Hidden();
      and
      unHidden();
      the same Hidden function that was called upon starting the app works perfectly.

      The first function draws the datagrid with cellrenderer.

      [CODE]
      /*---------------------DATAGRID W/Checkboxes--------------------*/

      function unHidden(){
      thisIndex = grid.selectedIndex;
      trace (thisIndex);
      grid.removeAllColumns();
      /* Set layout properties.*/

      var leftLayout:Number = 64.7;
      var topLayout:Number = 310;
      var widthLayout:Number = 530;
      grid.setSize(widthLayout, 185);
      grid.move(leftLayout, topLayout);
      grid.addColumn(new DataGridColumn("Active"));
      grid.addColumn(new DataGridColumn("Name"));
      grid.addColumn(new DataGridColumn("Artist"));

      /* Assign data provider to the grid to populate it.*/
      grid.dataProvider = myDP;

      grid.getColumnAt(0).width = 60;
      grid.getColumnAt(1).width = 225;
      grid.getColumnAt(2).width = 225;
      grid.resizableColumns = false;
      grid.vScrollPolicy = "auto";
      grid.setStyle("alternatingRowColors", [0xffffff,0xE6E9EE]);

      /* Assign cell renderer classes to specific columns.*/
      grid.getColumnAt(0).cellRenderer = "CheckBoxCell";
      grid.sortable=false;
      grid.selectedIndex = thisIndex;
      }
      [/CODE]



      The second without cellrenderer, this is the function that seems to work perfectly when called by a toggled button, but not when called initially.


      [CODE]
      /*--------------------DATAGRID W/O Checkboxes-------------------*/

      function Hidden(){
      thisIndex = grid.selectedIndex;
      grid.removeAllColumns();

      /* Set layout properties.*/

      var leftLayout:Number = 64.7;
      var topLayout:Number = 310;
      var widthLayout:Number = 530;

      /* Create a DataGrid.*/
      grid.setSize(widthLayout, 185);
      grid.move(leftLayout, topLayout);
      grid.addColumn(new DataGridColumn("Name"));
      grid.addColumn(new DataGridColumn("Artist"));

      /* Assign data provider to the grid to populate it.*/
      grid.dataProvider = myDP;


      grid.getColumnAt(0).width = 225;
      grid.getColumnAt(1).width = 225;
      grid.resizableColumns = false;
      grid.vScrollPolicy = "auto";
      grid.setStyle("alternatingRowColors", [0xffffff,0xE6E9EE]);
      grid.sortableColumns = false;
      if(thisIndex == undefined){
      thisIndex=0;
      }
      grid.selectedIndex = thisIndex;
      if(grid.selectedIndex==0){
      getLoud();
      }
      trace(thisIndex);
      } [/CODE]


      Here is the call, to the hidden function. It never fails to draw the datagrid,
      and never succeds in selecting the first index.
      [CODE]
      /*------------------------INIT-------------------------*/
      Hidden();
      [/CODE]


      This is the button code I'm using to toggle that calls the Hidden(); function
      again but is allways succesfull in setting the selectedIndex.


      [CODE]
      /*-----------------LIVE EDIT----------------*/

      var live=false;
      liveEdit.onRelease = function (){
      if(live == false){
      unHidden();
      live=true;
      } else {
      Hidden();
      live=false;
      }
      }
      [/CODE]