4 Replies Latest reply on Apr 27, 2010 9:32 AM by asafdsadfasddfsas

    Simple Datagrid Question

    playwiz Level 1

          Hey guys!  Here's my question:  I want to know how I can get a specific column value of a datagrid selected by the mouse as opposed to the entire row.  My goal is to have a picture displayed onMouseOver depending on which item the mouse is on.

       

      Thanks.

        • 1. Re: Simple Datagrid Question
          asafdsadfasddfsas Level 1

          You need to have a event handler for ListEvent.

           

          The ListEvent dispatched by the datagrid will have the following properties:

           

          columnIndex

          rowIndex

           

          example:

          public function itemRollOverFunction(le:ListEvent):void{

               Alert.show(le.columnIndex.toString()+le.rowIndex.toString());

          }


          <mx:DataGrid itemRollOver="itemRollOverFunction(event)"/>

           

          Hope it helps.

           

          Thanks,

          Sathish.

          • 2. Re: Simple Datagrid Question
            Matt Le Fevre Level 4

            had this test app i made a while back lying around, should get you started

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" verticalAlign="top"
                horizontalAlign="center" backgroundGradientColors="[0x000000,0x323232]" paddingTop="0" viewSourceURL="srcview/index.html">
                
                <mx:XMLList id="employees">
                    <employee>
                        <name>Blahdfklghdf</name>
                        <phone>555-219-2270</phone>
                        <image>http://www.unicamultimedia.com/p1/images/skyline-stock.jpg</image>
                    </employee>
                    <employee>
                        <name>Testttttttttttttttttt</name>
                        <phone>555-219-2012</phone>
                        <image>http://www.google.co.uk/intl/en_uk/images/logo.gif</image>
                    </employee>
                    <employee>
                        <name>Test Test</name>
                        <phone>555-219-2012</phone>
                        <image>http://drboycefinance.files.wordpress.com/2008/12/04_03_1-stock-market-prices_web1.jpg</image>
                    </employee>
                </mx:XMLList>
                
                <mx:Script>
                    <![CDATA[
                        import mx.events.ListEvent;
                        private function doThis(event:ListEvent):void
                        {
                            dg.selectedIndex = event.rowIndex;
                        }
                    ]]>
                </mx:Script>
                
                <mx:DataGrid id="dg" color="0x323232" width="675" itemRollOver="doThis(event)" rowCount="3" dataProvider="{employees}" x="14" y="62">
                    <mx:columns>
                        <mx:DataGridColumn dataField="name" headerText="Item 1"/>
                        <mx:DataGridColumn dataField="phone" headerText="Item 2"/>
                    </mx:columns>
                </mx:DataGrid>
                <mx:Image id="img1" x="162" y="201" width="377" height="269" scaleContent="true" source="{dg.selectedItem.image}"/>  
                
            </mx:Application>
            
            1 person found this helpful
            • 3. Re: Simple Datagrid Question
              playwiz Level 1

              Wow, you guys are awesome!  Thanks!!   And Sathish: thanks for spending your first post to answer my question -- makes me feel special.

              • 4. Re: Simple Datagrid Question
                asafdsadfasddfsas Level 1

                playwiz,

                 

                it's my pleasure. This is my first day here. I am enjoying it.