Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 985561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:11:03+00:00 2026-05-16T05:11:03+00:00

What I am trying to do is have a user input his data into

  • 0

What I am trying to do is have a user input his data into multiple textboxes, then once the data is entered it is displayed on the datagrid at runtime. The problem is when I run the app I click my button but no information entered is added to datagrid. My textboxes are also supposed to clear once the button is pressed but again nothing happens. Here is my code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
    <![CDATA[

     import mx.collections.ArrayCollection;

     [Bindable]private var dgItems:ArrayCollection;
     [Bindable]public var temp:Object;


     public function addItem(evt:Event):void {
     //add item if the text input fields are not empty
      if(name_input.text != ""&& location_input.text !="") {
     //create a temporary Object
      temp = myDG.selectedItem;
      var temp:Object = new Object();
     //add the text from the textfields to the object
      temp = {name:name_input.text, location:location_input.text};

     //this will add the object to the ArrayColldection (wich is binded with the DataGrid)
      dgItems.addItem(temp);
     //clear the input fields
      name_input.text = "";
       location_input.text ="";
      }
     }
    ]]>
   </mx:Script>

 <mx:DataGrid  x="97" y="110"  dataProvider="{dgItems}" id="myDG">
  <mx:columns>
   <mx:DataGridColumn headerText="Column 1" dataField="name:"/>
   <mx:DataGridColumn headerText="Column 2" dataField="location:"/>

  </mx:columns>
 </mx:DataGrid>
 <mx:Button x="97" y="51" label="add" click="addItem(event)"/>
 <mx:TextInput x="117" y="300" id="location_input"/>
 <mx:TextInput x="117" y="340" id="name_input"/>
</mx:Application>

Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:11:03+00:00Added an answer on May 16, 2026 at 5:11 am

    Your code has lots of errors. First, you were not initializing the dgItems array collection, so it’s value was null. You would get errors when you tried to “addItem” to the null object.

    Second you were trying to access the selectedItem of the dataGrid before initializing the DataGrid’s ArrayCollection dataProvider. No items in the list, there can be no selectedItem.

    Third, you’re creating the new object twice; once with the ‘new Object’ line and again with
    the in-line syntax for defining ojects: ‘{}

    Fourth, the datafield properties on the DataGridColumn both had colons in them, but the object’s properties did not.

    I hope this helps.

        <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Script>
            <![CDATA[
    
                import mx.collections.ArrayCollection;
    
                // array collection was never initialized; you can't items to a null object 
                [Bindable]private var dgItems:ArrayCollection = new ArrayCollection();
    // not needed
    //          [Bindable]public var temp:Object;
    
    
                public function addItem(evt:Event):void {
                    //add item if the text input fields are not empty
                    if(name_input.text != ""&& location_input.text !="") {
                        //create a temporary Object
                        // this line of code serves no purpos
                        //                  temp = myDG.selectedItem;
                        var temp:Object // = new Object();
                        //add the text from the textfields to the object
                        temp = {name:name_input.text, location:location_input.text};
    
                        //this will add the object to the ArrayColldection (wich is binded with the DataGrid)
                        dgItems.addItem(temp);
                        //clear the input fields
                        name_input.text = "";
                        location_input.text ="";
                    }
                }
            ]]>
        </mx:Script>
    
        <mx:DataGrid  x="97" y="110"  dataProvider="{dgItems}" id="myDG">
            <mx:columns>
                <!-- need to remove the colons from the data field -->
                <mx:DataGridColumn headerText="Column 1" dataField="name"/>
                <mx:DataGridColumn headerText="Column 2" dataField="location"/>
    
            </mx:columns>
        </mx:DataGrid>
        <mx:Button x="97" y="51" label="add" click="addItem(event)"/>
        <mx:TextInput x="117" y="300" id="location_input"/>
        <mx:TextInput x="117" y="340" id="name_input"/>
    </mx:Application>
    

    Many of these errors were easy to catch as soon as I launched the debugger. If you aren’t already using it, I suggest doing some reading up on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I'm trying to do is have the user input a number, and then
I am trying to have the user input a number, and then that number
Using XCode 3.2, What I'm trying to do is have the user input data
I am trying to have a user input a 1,2,3,4,5,6. Then have that integer
I'm trying I have a string that I pass into my function from user
Trying to have a user input their name, copy that variable to a file,
I have been trying to retrieve unicode user input in my Java application for
I'm trying to have the user pick an audio file and store the path
In Android, I'm trying trying to have the user enter a place they name,
I have a User model. I am trying to update a confirm attribute from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.