4 Replies Latest reply on Feb 5, 2007 10:56 AM by kiamber

    Passing Data From a DataGrid to a Form Item

    kiamber Level 1
      I am new to Flex, and I currently have a DataGrid that shows a query result of many items. If I select one I pass the ID to prepopulate an Edit form. It is not passing it. Below is my code that I pass from the DataGrid:

      //this function is called when the user clicks the "Edit" button
      private function goToLocations():void {
      var objSelectedNetwork:Object = new Object;
      objSelectedNetwork = thisId;
      var objectEvent:ObjectEvent = new ObjectEvent("DisplayEditNetwork",true);
      objectEvent.objToPass = objSelectedNetwork;

      I then have a EventListener call and pass the ID to the Edit Form:
      private function init():void {
      private function displayEditNetwork(event:ObjectEvent):void {
      networkEdit.thisId = event.objToPass as int;
      NetworkAccordion.selectedChild = NetworkEdit;

      and finally, I have the setting of the ID:

      public function setNetworkId(event:ObjectEvent):void {

      <mx:method name="getById" result="receiveSelectedNetwork(event)"/> -------- this calls my getById method:
      private function receiveSelectedNetwork(event:ResultEvent):void {
      if (thisId != 0){
      var editNetworkId:int = 0;
      editNetworkId = thisId;

      The alert that's currently on the DataGrid template alerts the correct ID, but the other alerts have a value of "0". Any suggestions would be greatly appreciated!
        • 1. Re: Passing Data From a DataGrid to a Form Item
          kiamber Level 1
          I have changed my code on the template with the DataGrid to :
          private function submitEditForm():void {
          //enable controls for editing
          //var thisId:int = 0;
          var e:Event = new Event("thisId");
          thisId = dgNetworks.selectedItem.NetworkId;
          It appears as though changing the var to an Event is capturing the data, but the Event continues to run. I have an alert on the Form template and the alert continues to run. Does anyone know how to stop this after the function runs and sets my data?
          • 2. Re: Passing Data From a DataGrid to a Form Item
            davidmedifit Level 1
            Can we take a step back for a moment? You have a datagrid, that is populated with results of a remoteObject, and what I think you want to do is the following:

            1) When the user clicks on a datagrid item, put the details into an editable form
            2) You want to call another remoteObject method, pass it the ID from the selected datagrid item, and have the results populate the editable form.

            Question: Are the datagrid and editable form in their own components, or in the main application? I have a feeling you are making this harder on yourself than you need to.


            • 3. Re: Passing Data From a DataGrid to a Form Item
              kiamber Level 1
              Hello David,

              I have a main.mxml, a display.mxml, and an edit.mxml. The main.mxml has the addEventListener and the function to pass the object to the edit.mxml. I now have the "ID" that should be displayed on the form as an "alert" within the function that should call my cfc and set the values in the form. So, I know that the value is being passed correctly. I also have the event stopped after one instance. I think I'm missing something between the call to the cfc method and the form itself. Is there an example of the kind of functionality that I'm trying to produce? Thank you in advance for your prompt response!
              • 4. Re: Passing Data From a DataGrid to a Form Item
                kiamber Level 1
                Hello David,

                The problem has been resolved, and I wanted to pass along this bit of info just in case someone runs across this issue. I had a conflict with my naming conventions. I have a network.as. I had my import in place, and I had this code below:

                network:Network as event.result as Network (this did not work)

                I had to pass it the exact folder location of the network.as like:

                network:src.model.theLocation.Network = event.result as src.model.theLocation.Network

                Thank you for your response!