troubleshooting Question

My DataGrid isnt populating when i add a search button.

Avatar of Brant Snow
Brant Snow asked on
Apache Flex
10 Comments1 Solution1862 ViewsLast Modified:
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!!!!
ASKER CERTIFIED SOLUTION
Gary Benade

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros