1 Reply Latest reply on Nov 15, 2007 11:02 PM by ntsiii

    Detecting clicks on a datagrid

    vij010
      Hi,
      I have this following code ....
      [code]
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      creationComplete="initApp()" height="377" width="572" borderStyle="solid">
      <mx:Script><![CDATA[
      import mx.collections.XMLListCollection;
      import mx.controls.Alert;
      import flash.events.Event
      import mx.events.ListEvent
      import mx.events.ListEvent;
      [Bindable]
      private var _xlcDP:XMLListCollection;




      public function initApp():void
      {
      var xmlDP:XML =
      <data>
      <item name ="Potatoes" quantity="200" price="2.50"></item>
      <item name ="Onions" quantity="400" price="3.50"></item>
      <item name ="Carrots" quantity="100" price="4.00"></item>
      <item name ="Ginger" quantity="400" price="3.00"></item>
      <item name ="Eggs" quantity="200" price="3.00"></item>
      <item name ="Salt" quantity="400" price="2.50"></item>
      <item name ="Sugar" quantity="200" price="2.50"></item>
      <item name ="Apples" quantity="300" price="2.50" ></item>
      <item name ="Bananas" quantity="40" price="4.00"></item>
      <item name ="Grapes" quantity="300" price="3.00"></item>
      </data>
      _xlcDP = new XMLListCollection(xmlDP.item);
      }//initApp

      public function checkvalue():void{
      if(qty.text==''){
      Alert.show('Enter Quantity Field ','Application Error!')
      }
      else {
      var selectedtext:String=
      var t:Number=Number(qty.text)
      var f:Number=t * dgSource.selectedItem.@price
      pricedisp.text='RM' +String(f);
      }
      }
      ]]></mx:Script>


      <mx:NumberValidator source="{qty}" property="text" invalidCharError="invalid characters"
      minValue="2" domain="int" invalidFormatCharsError="Only numbers!"
      lowerThanMinError="Field cannot have value less than RM 2" trigger="{mysub}" triggerEvent="click" />
      <mx:Panel x="10" y="10" width="553" height="357" layout="absolute" title="Simple Flex Item Calculator" alpha="1.0">
      <mx:DataGrid id="dgSource" dataProvider="{_xlcDP}" editable="false" liveScrolling="true" columnWidth="0" paddingLeft="20" x="10" y="10" enabled="true" width="316">
      <mx:columns>
      <mx:Array>
      <mx:DataGridColumn headerText="Item" dataField="@name" textAlign="center"/>
      <mx:DataGridColumn headerText="Quantity" dataField="@quantity" textAlign="center" />
      <mx:DataGridColumn headerText="Price(RM Per Kg)" dataField="@price" textAlign="center" />
      </mx:Array>
      </mx:columns>
      </mx:DataGrid>
      <mx:TextInput id="qty" editable="true" x="148" y="171" width="71"/>
      <mx:Label text="Enter your quantity" paddingLeft="20" x="10" y="173"/>
      <mx:Button label="Submit" x="227" y="171" id="mysub" click="checkvalue()"/>
      <mx:VRule x="334" y="0" width="4" height="317"/>
      <mx:TextArea x="346" y="10" width="173" height="297" text="This simple application calculates the prices with the quantities and gives you the final result" editable="false"/>
      <mx:Label x="10" y="208" text="Item :"/>
      <mx:Label x="17" y="230" text="Qty :"/>
      <mx:Text x="52" y="208" text="{dgSource.selectedItem.@name}"/>
      <mx:Text x="52" y="230" text="{dgSource.selectedItem.@quantity}"/>
      <mx:Label x="15" y="256" text="New Price :"/>
      <mx:Text x="79" y="256" id="pricedisp" enabled="false" color="red"/>
      </mx:Panel>
      </mx:Application>
      [/code]

      So, what I need is to detect if the datagrid has been clicked, to warn the user to select a row before submitting, I see that there's a class called ListEvent, but I am unable to use it, as the compiler says I can't have another public keyword(I just copied the code from the help)

      How to do it ?