2 Replies Latest reply on Aug 16, 2006 8:08 PM by doug777

    Highlight problem with DataGrid

    doug777
      I have simplified, but this still shows the error:

      I have two products A and B and user can choose to buy 1 or 2 of either or both.

      The user must then choose from a set of possible add-ons for each one of each product.

      I want to display in a DataGrid the possibilities for each item. These details are in an ArrayCollection detailsArray where element 0 contains the details for product A and element 1 for B.

      So (because it's really more complex than this) I set up an array choiceArray containing the original choices, so if user wants 2 of A and 1 of B, this array will contain 0,0,1 for example.

      I don't want to amend detailsArray, so I set up a new ArrayCollection which will be the source for the grid's dataProvider:

      var item:Object;
      var newitem:Object;
      var newArray:ArrayCollection = new ArrayCollection();
      for(var j:uint=0; j<choiceArray.length; j++){
      item = new Object();//this line seems to make no difference, I added it when trying to solve the problem
      //get the correct item's details
      item = detailsArray[choiceArray[j]];
      newitem = new Object();
      //add each detail to the new object
      for(var k:String in item){
      newitem[k] = item[k];
      }
      //add a sequence number to each grid row
      newitem.seq = (j+1);
      //add this row to the new array
      newArray.addItem(newitem);
      Alert.show(ObjectUtil.toString(newArray));//shows uid
      }
      myGrid.dataProvider = newArray;
      myGrid.selectedIndex = 0;

      If the customer selects 1 of either item or 1 each of both items there is no problem.

      However, if the user chooses 2 of either or both items, in the DataGrid the second item in the list is highlighted and even if you select row 1 (and it is correctly selected) the highlight remains on row 2. It is only the highlight that is incorrect.

      The reason seems to be that the uid and mx-internal-uid in newArray is the same for all items where choiceArray had the same data.

      Why should this be? And what can I do to solve the problem?

      Doug
        • 1. Re: Highlight problem with DataGrid
          doug777 Level 1
          Also, if I try to step through the items in the DataGrid:

          -- if choiceArray == 0,0 and myGrid.selectedIndex == 0 and I then have:

          myGrid.selectedIndex = myGrid.selectedIndex + 1;

          After this line myGrid.selectedIndex is still 0 (and no errors occur).

          -- if choiceArray == 0,1 and myGrid.selectedIndex == 0 and I then have:

          myGrid.selectedIndex = myGrid.selectedIndex + 1;

          After this line myGrid.selectedIndex is changed to 1.

          Any help on this would be appreciated,

          Doug
          • 2. Re: Highlight problem with DataGrid
            doug777 Level 1
            This appears to solve the problem.

            import mx.utils.UIDUtil;

            var newuid:String;

            then inside the loop:

            newuid = UIDUtil.createUID();

            then after the line -- item = detailsArray[choiceArray[j]];

            add the line

            item.mx_internal_uid = newuid;

            Doug