0

I have to work with rss string. Basically I have to work with Data in grid.

I have following function on change handler of datagrid; it means when I am click on any item, selected datafield row will bind to the label as per shown below:

protected function dg_selectionChangeHandler(event:GridSelectionEvent):void
{               
            const eventGrid:Grid = event.currentTarget.grid;
            var currentIndx:int = eventGrid.selectedIndex;
            var currentDataItem:Object = eventGrid.selectedItem;
            selIndex.text = String(currentIndx);
            txtSource.text = String(currentDataItem.link);              
            txtSource.visible = false;
            HttpGetUrl(txtSource.text);
}

it works fine for me. Whenever I choose any item in grid, it bind that rows value to label which I defind.

But, value is not being populated when datagrid initialize for the first time or I should say when for the first time datagrid comes on screen, values of that row does not populated to the labels when selectedindex = 0. I also want those values when datagrid initialize for the first time also Code as shown below:

protected function dg_creationCompleteHandler(event:FlexEvent):void
{               
            const eventGrid:Grid = event.currentTarget.grid;
            var currentIndx:int = eventGrid.selectedIndex;
            var currentDataItem:Object = eventGrid.selectedItem;
            selIndex.text = String(currentIndx);
            txtSource.text = String(eventGrid.selectedItem.link);
            txtSource.visible = true;
}

and code for datagrid is:

<s:DataGrid id="dgNews" x="10" y="70" width="300" height="623" click="dg_clickHandler(event)" color="#000000" visible="true" horizontalScrollPolicy="off" 
            variableRowHeight="true" selectionChange="dg_selectionChangeHandler(event)" creationComplete="dg_creationCompleteHandler(event)" selectedIndex="0">
    <s:columns>
        <s:ArrayList>               
            <s:GridColumn dataField="title" headerText="Title" width="300"/>
        </s:ArrayList>
    </s:columns>
</s:DataGrid>

Can anyone told me how to bind default selectedindex = 0 value to the labels I define?

Naveed Mansuri
  • 439
  • 1
  • 5
  • 13

1 Answers1

0

In that case is not binding... you are just giving some values of the selected row to some textinputs... Using binding means you make some glue between your datagrid and some other components inputs in your case To do that you have to do something like this:

  <s:TextInput text="{dgNews.selectedItem.link}"/>

This way the input binds to the selected row value of your grid.

While the other thing maybe is not clear is the fact that when the grid is created it doesn't mean that it has taken its dataprovider's data yet so there is no selected row... so you don't need that event listener binding will handle that... this way you don't even need the selection event... too

In few words this part of code is all mxml and just the way of the textinput sample you handle it without any function.

If you want to select the first row when data arrives than you just need to handle that event and set the selected index of the grid.

daniel
  • 1,152
  • 2
  • 15
  • 33