3 Replies Latest reply on Apr 17, 2008 2:18 PM by peterskeeter

    Edit a dataGrid

    Dizzia Level 1
      Alright, let me preface this with the fact that I'm new to flex.

      I have been using tutorials, writeups, blogs, etc to try to solve my problems. And every so often I get one that just dumbfounds me.

      So I have a datagrid that's being filled up with an assortment of text input / values, they fill when the user clicks a button called 'add'.
      My problem, is that I have a button called edit, so the user can click in the datagrid, and then instead of adding a new row, simply edit the row that already exists in the datagrid.
      I also have a button called remove, that I'd like to setup to remove the currently selected row.
      *EDIT*One last thing (hoping this will be possible) I'd like to get the currently selected row to repopulate the original text input boxes / values that were used to originally populate it with the add command.*EDIT* got this working

      Just to be clear, I can throw the data into the thing, Now I just need a way to get the data out. Half way to getting this working I think.

      Thanks for any and all help.
        • 1. Re: Edit a dataGrid
          peterskeeter
          You use a dataprovider to fill the datagrid right (say if an Arraycollection ?) ?
          Simply do work on that dataprovider using the Arraycollection functions
          like:
          To get the selected item in your DG:

          var myObj:Object = new Object();
          myObj = myArrayCollection.getItemAt(myDataGrid.selectedIndex)
          Alert.show(myObj.firstname + " is the selected firstname in my DG");

          To delete an item in the Arraycollection(and hence the DG):

          myArrayCollection.removeItemAt(myDataGrid.selectedIndex);

          Once you do work on your arraycollection, because its a dataprovider to your DG the DG will reflect those changes...
          • 2. Re: Edit a dataGrid
            Dizzia Level 1
            This stuff is all pretty new to me. Got the removal to work. I'm going to run to class and see if I can get the edit function to work when I get back.

            Thanks pete!
            • 3. Re: Edit a dataGrid
              peterskeeter Level 1
              When editing in your DG, once you have the new , updated data
              you need to use the setItemAt function on your Arraycollection.

              i.e here is a snippet :

              var am:AssessmentMark = new AssessmentMark();
              am.***_mark = e.target.the_val;
              am.id = AC_class_students_marks.getItemAt(DG_class_students.selectedIndex).id;
              am.rpt_period_id = 1;
              am.sc_id = StudentClass(COMBO_my_classes.selectedItem).sc_id;

              var obj:Object = new Object();
              obj = AC_assessmentmarks.getItemAt(b);
              AC_assessmentmarks.setItemAt(am,b);
              AC_assessmentmarks.itemUpdated(am);

              Basically i create a new "am" object and fill its properties with whatever.
              Once I've done that I use this update "am" object and setItem that object into my arraycollection, then call the itemupdated function to tell it that something has been updated so you see the change in your DG...