3 Replies Latest reply on May 9, 2008 12:51 PM by Jaz Chana

    Selecting Item(s) on a DataGrid

    Jaz Chana
      Simple questions, couldn't find a simple answer however. I want to be able to select and item (and possibly later items) on a datagrid from the click of a button. I've tried set the selectedIndex property on the datagrid, but this does nothing. Does anyone have a solution to this?

        • 1. Re: Selecting Item(s) on a DataGrid
          atta707 Level 2
          Both selectedIndex and selectedIndices should work:

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

          import mx.collections.ArrayCollection;

          var gridData:ArrayCollection = new ArrayCollection(
          new Array(
          {id:123, company:'Microsoft'},
          {id:456, company:'Adobe'},
          {id:789, company:'Yahoo!'}

          <mx:Button label="Select Row(s)" click="dg.selectedIndices=[0, 1, 2]"/>

          <mx:DataGrid id="dg" dataProvider="{this.gridData}" allowMultipleSelection="true">
          <mx:DataGridColumn headerText="ID" dataField="id"/>
          <mx:DataGridColumn headerText="Company" dataField="company"/>

          • 2. Re: Selecting Item(s) on a DataGrid
            Gregory Lafrance Level 6
            This code seem to work:

            • 3. Selecting Item(s) on a DataGrid
              Jaz Chana Level 1
              Both those solutions worked on their own, but when I tried to integrate them with my current project I couldn't seem to get them to work. Until I moved my dg.selectedIndex statement underneath the currentState=null; statement. For some reason, i'm guessing because it resets the view, that statement was preventing the selectedIndex to be set. , Anyways, thanks for the help guys much appreicated.