Quote:
Originally Posted by bon_t
HA colleague said that he recalled seeing a datagrid where you can click on an empty row to add a new row. I Googled this but it seems that you have to add a dummy row with something like "Click to add row" to do this.
|
Yep, that is a common practice. Here is how you can detect a click inside of the ADG that is not on a row:
Code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="356" height="276">
<fx:Script>
<![CDATA[
import mx.collections.ArrayList;
import mx.controls.Alert;
[Bindable]
private var stateArray:ArrayList = new ArrayList(
[{label:"AL", data:"Montgomery"},
{label:"AK", data:"Juneau"},
{label:"AR", data:"Little Rock"}]);
protected function adg1_clickHandler(event:MouseEvent):void
{
if(getQualifiedClassName(event.target) == 'mx.controls.listClasses::AdvancedListBaseContentHolder')
{
Alert.show('Click!');
}
}
]]>
</fx:Script>
<mx:AdvancedDataGrid id="adg1" x="10" y="10"
width="339" height="254"
dataProvider="{stateArray}"
click="adg1_clickHandler(event)">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="label" headerText="ID"/>
<mx:AdvancedDataGridColumn dataField="data" headerText="Name"/>
</mx:columns>
</mx:AdvancedDataGrid>
</s:Application>
I only tested this in Flex 4.5.1 and it likely won't work in older versions. There is probably a better way to do this too, but I didn't see one immediately apparent and I've never tried to do this before; I've always gone the route of adding a dummy row.