We help IT Professionals succeed at work.
Get Started

My DataGrid isnt populating when i add a search button.

Brant Snow
Brant Snow asked
on
1,861 Views
Last Modified: 2010-04-21
K so i have an advanced datagrid that is working fine using this the code below and importing the xml (i listed the xml after the code)  After this example you will see my new code that is adding a search button.  I dont get any errors when running it but i get a warning and the datagrid is not being populated.

The warning says:
Data binding will not be able to detect assignments to "myAC".      
Its on line 62 and i will add a little <!-- Here is the warning --> in the new code located at the bottom.


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<!-- Code working without search button -->
<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="myHS.send() " >
<mx:HTTPService id="myHS" url="data.xml" result="myAC = myHS.lastResult.results.row as ArrayCollection"/>
<mx:Script>
  <![CDATA[
    import mx.collections.ArrayCollection;
    [Bindable]
    private var myAC:ArrayCollection;
  ]]>
</mx:Script>


<mx:Panel width="612" height="456" layout="absolute" horizontalCenter="0" verticalCenter="-18" resizeEffect="Resize" title="Top 25 Report">


<mx:AdvancedDataGrid id="myADG" dataProvider="{myAC}" width="542" variableRowHeight="true" wordWrap="true" height="422" horizontalCenter="0" verticalCenter="2">
  <mx:columns>
    <mx:AdvancedDataGridColumn headerText="ID" dataField="DIST_ID" styleFunction="highlightCost"/>
    <mx:AdvancedDataGridColumn headerText="ROMAN NAME 1" dataField="ROMAN_NAME_1"/>
    <mx:AdvancedDataGridColumn headerText="ROMAN NAME 2" dataField="ROMAN_NAME_2" />
  </mx:columns>
</mx:AdvancedDataGrid>

</mx:Panel>      
      
      <mx:Script>
        <![CDATA[

        public function highlightCost(data:Object, column:AdvancedDataGridColumn):Object
        {
            if (data.DIST_ID > 3000)
                return { color : "blue" };
            else
                return null;
        }

        ]]>
    </mx:Script>
</mx:Application>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
The xml file looks like this
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="ISO-8859-1"?>

<results>

  <row>

    <DIST_ID>104831</DIST_ID>

    <ROMAN_NAME_1>Doerrier, David</ROMAN_NAME_1>

    <ROMAN_NAME_2>null</ROMAN_NAME_2>

  </row>

  <row>

    <DIST_ID>104832</DIST_ID>

    <ROMAN_NAME_1>Pereira Coutinho, Benjamin</ROMAN_NAME_1>

    <ROMAN_NAME_2>null</ROMAN_NAME_2>

  </row>

  <row>

    <DIST_ID>104833</DIST_ID>

    <ROMAN_NAME_1>sutton, David A</ROMAN_NAME_1>

    <ROMAN_NAME_2>null</ROMAN_NAME_2>

  </row>

  <row>

    <DIST_ID>104834</DIST_ID>

    <ROMAN_NAME_1>Berdin, Frian Joy Y</ROMAN_NAME_1>

    <ROMAN_NAME_2>null</ROMAN_NAME_2>

  </row>

  <row>

    <DIST_ID>104835</DIST_ID>

    <ROMAN_NAME_1>Good Health Maui Inc</ROMAN_NAME_1>

    <ROMAN_NAME_2>null</ROMAN_NAME_2>

  </row>

</results>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
new code with search button
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="myHS.send() " >
<mx:HTTPService id="myHS" url="data.xml" result="myAC = myHS.lastResult.results.row as ArrayCollection"/>
<mx:Script>
      <![CDATA[
            import mx.collections.SortField;
            import mx.collections.Sort;
            import mx.collections.IViewCursor;
            import mx.events.FlexEvent;
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            
            [Bindable]
            
            private var cursor:IViewCursor;
            private var myAC:ArrayCollection;
            
            private function initApp():void
                  {
                  this.myHS.send();
                  }
                  
            private function onResult(evt:ResultEvent):void
                  {
                        var sort:Sort = new Sort();
                        sort.fields = [ new SortField("ID",true) ];
                        this.myAC = evt.result.data.region;
                        this.myAC.sort = sort;
                        this.myAC.refresh();
                        this.cursor = this.myAC.createCursor();
                  }
                  
            private function searchID():void
                  {
                        if(search_ti.text != "")
                              {
                                    if(this.cursor.findFirst({ID:search_ti.text})){
                                          var idx:int = this.myAC.getItemIndex(this.cursor.current);
                                          this.myADG.scrollToIndex(idx);
                                          this.myADG.selectedItem = this.cursor.current;
                                    
                              
                  
                                    }
                              }
                  }
      ]]>
</mx:Script>
<mx:Form x="0" y="165">
            <mx:FormItem label="Search">
                  <mx:TextInput id="search_ti"/>
            </mx:FormItem>
                  <mx:FormItem>
                        <mx:Button label="Search ID" click="searchID()"/>
                  </mx:FormItem>
      </mx:Form>
      
<mx:Panel width="612" height="456" layout="absolute" horizontalCenter="0" verticalCenter="-18" resizeEffect="Resize" title="Top 25 Report">


<!--Here is where the warning is--><mx:AdvancedDataGrid id="myADG" dataProvider="{myAC}" width="542" variableRowHeight="true" wordWrap="true" height="422" horizontalCenter="0" verticalCenter="2">
  <mx:columns>
    <mx:AdvancedDataGridColumn headerText="ID" dataField="DIST_ID" styleFunction="highlightID"/>
    <mx:AdvancedDataGridColumn headerText="ROMAN NAME 1" dataField="ROMAN_NAME_1"/>
    <mx:AdvancedDataGridColumn headerText="ROMAN NAME 2" dataField="ROMAN_NAME_2" />
  </mx:columns>
</mx:AdvancedDataGrid>
      
</mx:Panel>





      <mx:Script>
        <![CDATA[

        public function highlightID(data:Object, column:AdvancedDataGridColumn):Object
        {
            if (data.DIST_ID > 3000)
                return { color : "blue" };
            else
                return null;
        }

        ]]>
    </mx:Script>
</mx:Application>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Please Help!!!!
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE