Preventing Flex tree drop feedback - actionscript-3

I'd like to allow a user to reorder items within a Flex tree folder, but not move those items outside of the folder. I can prevent the outside drop from succeeding, but I'd like to give the user feedback (before the drop) that the drop will not succeed. I've found many examples regarding the drop action, but nothing that shows the correct feedback to the user.
According to the Tree documentation, I should be able to call DragManager.showFeedback(DragManager.NONE) during the dragOver event, but that's not working. A short sample project is included below. Is there any way to indicate to the user during a drag event that the drop will not succeed?
Thanks in advance for any solution!
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication 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="354"
height="480">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.core.IUIComponent;
import mx.core.mx_internal;
import mx.events.DragEvent;
import mx.events.FlexEvent;
import mx.managers.DragManager;
protected function tree_dragEnterHandler(event:DragEvent):void {
// only items can be dragged - not folders
if (tree.selectedItem.#type == "item") {
DragManager.acceptDragDrop(IUIComponent(event.currentTarget));
} else {
event.preventDefault();
DragManager.showFeedback(DragManager.NONE);
}
}
protected function tree_dragOverHandler(event:DragEvent):void {
var dropData:Object = tree.mx_internal::_dropData;
var dragItem:XML = event.dragSource.dataForFormat("treeItems")[0];
if (!dropData || !dropData.parent || !dragItem.parent() || dragItem.parent() != dropData.parent) {
trace("preventing drop");
DragManager.showFeedback(DragManager.NONE);
return;
}
trace("allowing drop");
DragManager.showFeedback(DragManager.MOVE);
}
protected function tree_dragDropHandler(event:DragEvent):void {
}
]]>
</fx:Script>
<fx:Declarations>
<fx:XML id="treeData">
<folder id="root"
label="root"
type="root">
<folder id="folder1"
label="Folder 1"
type="folder">
<folder id="folder2"
label="Folder 2"
type="folder">
<item id="item1"
label="Item 1"
type="item"/>
<item id="item2"
label="Item 2"
type="item"/>
<item id="item3"
label="Item 3"
type="item"/>
<item id="item4"
label="Item 4"
type="item"/>
<item id="item5"
label="Item 5"
type="item"/>
</folder>
</folder>
<folder id="folder3"
label="Folder 3"
type="folder"/>
<folder id="folder4"
label="Folder 4"
type="folder"/>
<folder id="folder5"
label="Folder 5"
type="folder"/>
</folder>
</fx:XML>
</fx:Declarations>
<mx:Tree id="tree"
left="29"
right="28"
top="28"
bottom="27"
dragEnabled="true"
dropEnabled="true"
dragMoveEnabled="true"
dataProvider="{treeData}"
labelField="#label"
dragEnter="tree_dragEnterHandler(event)"
dragOver="tree_dragOverHandler(event)"
dragDrop="tree_dragDropHandler(event)"
showRoot="false">
</mx:Tree>
</s:WindowedApplication>

It's frustrating that the default drag-and-drop functionality almost provides everything necessary to accomplish this, but not quite. It seems that IlyaZ's answer should work, but that may be a bug in Flex's mx:Tree control.
I ended up accomplishing this by rolling my own drag-and-drop implementation as SunilD alluded to. The code is included below for anyone who may run into the same problem in the future.
Note that there's still a small visual feedback issue when the user is dragging over the boundary between maxDropIndex and maxDropIndex+1: At the lower part of the boundary the drop indicator will shift to indicate that it's possible to drop an item at the folder level. I'm still looking for a good solution to this (can anyone point me to the tree source?).
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication 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="354"
height="480">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.core.DragSource;
import mx.core.IUIComponent;
import mx.core.mx_internal;
import mx.events.DragEvent;
import mx.events.FlexEvent;
import mx.managers.DragManager;
protected var dragging:Boolean = false;
protected var minDropIndex:int = 0;
protected var maxDropIndex:int = 0;
protected function tree_dragEnterHandler(event:DragEvent):void {
// only items can be dropped
if (event.dragSource.hasFormat("tree_item_node")) {
DragManager.acceptDragDrop(IUIComponent(event.currentTarget));
trace("accepting DragDrop");
} else {
event.preventDefault();
DragManager.showFeedback(DragManager.NONE);
trace("rejecting DragDrop");
}
}
protected function tree_dragOverHandler(event:DragEvent):void {
var index:int = tree.calculateDropIndex(event);
if (index < minDropIndex || index > maxDropIndex) {
trace("preventing drop");
DragManager.showFeedback(DragManager.NONE);
this.tree.hideDropFeedback(event);
return;
}
trace("allowing drop");
DragManager.showFeedback(DragManager.MOVE);
this.tree.showDropFeedback(event);
}
protected function tree_dragDropHandler(event:DragEvent):void {
trace("dragDropHandler");
}
protected function tree_mouseMoveHandler(event:MouseEvent):void {
// see if we should start a drag operation
if (event.buttonDown && !dragging && tree.selectedItem && tree.selectedItem.#type == "item") {
// TODO: calculate the min and max drag indices from currently-selected index
minDropIndex = 2;
maxDropIndex = 7;
// start the drag
dragging = true;
var dragSource:DragSource = new DragSource();
dragSource.addData(tree.selectedItem, "tree_item_node");
DragManager.doDrag(IUIComponent(event.currentTarget), dragSource, event);
}
}
protected function tree_dragCompleteHandler(event:DragEvent):void {
trace("dragComplete: no longer dragging");
this.tree.hideDropFeedback(event);
dragging = false;
}
]]>
</fx:Script>
<fx:Declarations>
<fx:XML id="treeData">
<folder id="root"
label="root"
type="root">
<folder id="folder1"
label="Folder 1"
type="folder">
<folder id="folder2"
label="Folder 2"
type="folder">
<item id="item1"
label="Item 1"
type="item"/>
<item id="item2"
label="Item 2"
type="item"/>
<item id="item3"
label="Item 3"
type="item"/>
<item id="item4"
label="Item 4"
type="item"/>
<item id="item5"
label="Item 5"
type="item"/>
</folder>
</folder>
<folder id="folder3"
label="Folder 3"
type="folder"/>
<folder id="folder4"
label="Folder 4"
type="folder"/>
<folder id="folder5"
label="Folder 5"
type="folder"/>
</folder>
</fx:XML>
</fx:Declarations>
<mx:Tree id="tree"
left="29"
right="28"
top="28"
bottom="27"
dragEnabled="false"
dropEnabled="false"
dataProvider="{treeData}"
labelField="#label"
dragEnter="tree_dragEnterHandler(event)"
dragOver="tree_dragOverHandler(event)"
dragDrop="tree_dragDropHandler(event)"
dragComplete="tree_dragCompleteHandler(event)"
mouseMove="tree_mouseMoveHandler(event)"
showRoot="false">
</mx:Tree>
</s:WindowedApplication>

Related

Flex bind variable has no effect

No matter what I do, I cannot have any effect on Flex MXML elements during initialization.
I want to display a different logo depending on whether a flashVar is true or not.
For some reason the flashvar has no effect on how the elements appear.
Am I missing anything ?
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:components="ru.kutu.grindplayer.views.components.*"
mouseEnabled="false"
implements="ru.kutu.grind.views.api.IMainView"
preinitialize="preinitialize(event)"
>
<s:states>
<s:State name="initializing" />
<s:State name="ready" />
<s:State name="error" />
</s:states>
<s:BorderContainer
id="logoContainer"
left="0" right="0"
top="0" bottom="0"
mouseEnabled="false"
includeIn="initializing"
backgroundColor="0x070707"
borderVisible = "false"
>
<s:Image
id="logoPaid"
verticalCenter="0"
horizontalCenter="0"
source="#Embed('/../assets/skin/dark.png')"
visible="{is_paid}"
/>
<s:Image
id="logoFree"
verticalCenter="0"
horizontalCenter="0"
source="#Embed('/../assets/skin/dark_free.png')"
visible="{!is_paid}"
/>
</s:BorderContainer>
<components:PlayerView
id="playerView"
left="0" right="0"
top="0" bottom="0"
visible="false"
visible.ready="true"
/>
<s:Label
id="errorDisplay"
width="80%"
mouseEnabled="false"
verticalCenter="0"
horizontalCenter="0"
includeIn="error"
itemCreationPolicy="immediate"
/>
<s:transitions>
<s:Transition
fromState="*" toState="*"
autoReverse="true"
interruptionBehavior="stop"
>
<s:Fade
target="{this}"
duration="300"
/>
</s:Transition>
</s:transitions>
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
[Bindable]
private var is_paid:Boolean;
public function set errorText(value:String):void {
errorDisplay.text = value;
}
public function initializing(is_paid:Boolean):void {
currentState = "initializing";
}
public function ready():void {
currentState = "ready";
}
public function error():void {
currentState = "error";
}
private function preinitialize(event:FlexEvent):void {
is_paid = FlexGlobals.topLevelApplication.parameters.is_paid;
}
]]>
</fx:Script>
I think you parse String into Boolean. Cause params names and values are String, try this instead:
is_paid = FlexGlobals.topLevelApplication.parameters.is_paid == 'true';

flex4 moduls data passing from one module to another module

I have a Flex 4 application that loads a two module. first module is user login module and second one is user balance. when user application start login screen is displayed. when user login this module pass to java and process some validations and return to the flex. in flex if user is valid pass that user name to the second module. in that module using that name again pass user name to java and get balance of that user.
but my code is not working?
am tring this code:-
modules.mxml
<?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" minWidth="955" minHeight="600" xmlns:views="views.*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<views:module2/>
<views:module1>
</views:module1>
</s:Application>
module1.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Module 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="400" height="300">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
protected function login_resultHandler(event:ResultEvent):void
{
if(har.text=="valid"){
var username:String = "module2.swf?" + "username=" +user.text;
bordercontainerlogin.visible=false;
}else if(har.text=="not-valid")
{
validation.text="! make sure user name & password correct";
}
else
validation.text=har.text
}
protected function user_focusInHandler(event:FocusEvent):void
{
if((user.text=="User name")||(user.text==""))
{
user.text="";
}
}
protected function user_focusOutHandler(event:FocusEvent):void
{
if((user.text=="User name")||(user.text==""))
{
user.text="User name";
}
}
protected function pass_focusInHandler(event:FocusEvent):void
{
pass.displayAsPassword=true;
if((pass.text=="Password")||(pass.text==""))
{
pass.text="";
}
}
protected function pass_focusOutHandler(event:FocusEvent):void
{
if((pass.text=="Password")||(pass.text==""))
{
pass.displayAsPassword=false;
pass.text="Password";
}
}
protected function button1_clickHandler(event:MouseEvent):void
{
if(((user.text=="User name")||(user.text=="")) || ((pass.text=="Password")||(pass.text=="")))
{
if((user.text=="User name")||(user.text==""))
{
//validation.text="! Make sure user name shouidn't be empty";
Alert.show(user.text); }
else if((pass.text=="Password")||(pass.text==""))
{
validation.text="! Make sure Password shouidn't be empty";
}
}
else
{
login.cancel();
login.send();
}
}
protected function button1_mouseOutHandler(event:MouseEvent):void
{
Mouse.cursor=MouseCursor.ARROW;
}
protected function button1_mouseOverHandler(event:MouseEvent):void
{
Mouse.cursor=MouseCursor.BUTTON;
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="login" url="http://192.168.1.4:8400/myapp/login" method="POST" result="login_resultHandler(event)">
<s:request xmlns="">
<myname>{user.text}</myname>
<passwd>{pass.text}</passwd>
</s:request>
</s:HTTPService>
</fx:Declarations>
<s:BorderContainer x="0" y="-1" width="100%" height="100%" id="bordercontainerlogin" backgroundColor="#fa0000" backgroundAlpha=".2">
<s:ModuleLoader id="modulerload"/>
<s:Panel width="257" height="205" fontWeight="bold" horizontalCenter="-44" verticalCenter="-56" id="loginpanel" visible="true" title="User Login">
<s:TextInput id="user" y="61" horizontalCenter="-3" text="User name" focusIn="user_focusInHandler(event)" focusOut="user_focusOutHandler(event)"/>
<s:TextInput id="pass" y="99" focusIn="pass_focusInHandler(event)"
focusOut="pass_focusOutHandler(event)" horizontalCenter="-3" text="Password"/>
<s:Button y="137" label="LOGIN" click="button1_clickHandler(event)" horizontalCenter="-4"
mouseOut="button1_mouseOutHandler(event)"
mouseOver="button1_mouseOverHandler(event)"/>
<s:Label id="validation" x="4" y="167" color="#D90D0D"/>
</s:Panel>
<!--<s:ComboBox id="resultData" dataProvider="{reg.lastResult.status}" visible="true" selectedIndex="0"/>-->
<s:TextInput id="har" x="43" y="149" text="{login.lastResult.status}" visible="false" />
</s:BorderContainer>
</s:Module>
module2.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Module 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="400" height="300" creationComplete="module1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
var username:String;
protected function getbalance_resultHandler(event:ResultEvent):void
{
username= this.loaderInfo.url.toString();
getbalance.cancel();
getbalance.send();
}
protected function module1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="getbalance" url="http://192.168.1.4:8400/myapp/getbalance" method="POST" result="getbalance_resultHandler(event)">
<s:request xmlns="">
<myname>{username}</myname>
</s:request>
</s:HTTPService>
</fx:Declarations>
<s:Label text="welcome {username}" id="welcomelabel" />
<s:TextInput text="{getbalance.lastResult.status}" id="balance"/>
</s:Module>
Because module2 is creationComplete in this time,So,you can Because module2 is creationComplete in this time,So,you can be in when login_resultHandler load module2

How to hide the contents of a flex data grid?

NOTE: I'm using FLEX 4.
Hi, I want to know if there is a way to hide the data of a data grid without hiding the data grid itself? I want the screen to open with the data grids appearing empty. I only want the contents of the data grid to be visible once the user has selected an option from a combo box. Is there a way to do this? (The reasons for this are sort of involved and not pleasant to explain, but it's something I have to do.)
Thanks!
You could set dataProvider of the data grid to null or an empty collection until ready to display your data.
By default, initialize null or an empty collection to the data grid. Then, when the desired combo box option is selected set the data grid data provider to valid data:
<?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">
<fx:Script>
<![CDATA[
import mx.collections.ArrayList;
import spark.events.IndexChangeEvent;
[Bindable]
public var data:ArrayList = new ArrayList([ "one", "two", "three" ]);
protected function combobox1_changeHandler(event:IndexChangeEvent):void
{
switch (comboBox.selectedItem)
{
case "Show data":
dataGrid.dataProvider = data;
break;
default:
dataGrid.dataProvider = null;
break;
}
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:DataGrid id="dataGrid"
dataProvider="{null}" />
<s:ComboBox id="comboBox"
change="combobox1_changeHandler(event)">
<s:dataProvider>
<s:ArrayList>
<fx:String>Show data</fx:String>
<fx:String>Hide data</fx:String>
</s:ArrayList>
</s:dataProvider>
</s:ComboBox>
</s:Application>
Another approach would be to use Flex state system.
You could define two states to control visibility of data in the data grid. Then, set the data provider according to the current state:
<?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"
currentState="hideData">
<s:states>
<s:State name="showData" />
<s:State name="hideData" />
</s:states>
<fx:Script>
<![CDATA[
import mx.collections.ArrayList;
import spark.events.IndexChangeEvent;
[Bindable]
public var data:ArrayList = new ArrayList([ "one", "two", "three" ]);
protected function combobox1_changeHandler(event:IndexChangeEvent):void
{
switch (comboBox.selectedItem)
{
case "Show data":
currentState = "showData";
break;
default:
currentState = "hideData";
break;
}
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:DataGrid id="dataGrid"
dataProvider.hideData="{null}"
dataProvider.showData="{data}" />
<s:ComboBox id="comboBox"
change="combobox1_changeHandler(event)">
<s:dataProvider>
<s:ArrayList>
<fx:String>Show data</fx:String>
<fx:String>Hide data</fx:String>
</s:ArrayList>
</s:dataProvider>
</s:ComboBox>
</s:Application>

FLEX DataGrid Column Modification

I am new in Flex. I want to display data in attached grid format. I found best way to display in DataGrid. But the CIs column has multiple entries so because of that other columns will duplicate. I want to avoid duplicate data in other columns. Attached screenshot is of excel, i want to achieve same format in Flex. I am using Flex 4.5
Best way I see to do what you want is to create a custom item renderer for the CLS column and have it render as a list control. That way, the CLS item in each row will only take up one row instead of multiple rows.
You can get some idea by following code... you can build logic using below concept for your implementation. Below example is sample not complete according to your requirement: -
<?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" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.core.UIComponent;
import mx.events.AdvancedDataGridEvent;
import mx.events.ListEvent;
[Bindable]
private var dpHierarchy:ArrayCollection= new ArrayCollection
([
{name:"Barbara Jennings", address: "Arizona", contact:999970, orders:["1"]},
{name:"Dana Binn", address: "Arizona", contact:9999130, orders:["2"]},
{name:"Joe Smith", address: "California", contact:9992929, orders:["3"]},
{name:"Alice Treu", address: "California", contact:9999230, orders:["4"]}
]);
private function addOrder():void
{
for(var i:int = 0 ; i < dpHierarchy.length; i++)
{
if(dropDownID.selectedItem.name == dpHierarchy[i].name)
{
var itemUpdated:Array = dpHierarchy[i].orders;
itemUpdated.push(orderNumber.text);
dpHierarchy[i].orders = itemUpdated;
dpHierarchy.itemUpdated(dpHierarchy[i]);
break;
}
}
}
]]>
</fx:Script>
<mx:VBox x="30" y="30" width="450" height="400">
<s:HGroup>
<s:Button label="Add Order" click="addOrder()"/>
<s:DropDownList id="dropDownID" dataProvider="{dpHierarchy}" labelField="name" selectedIndex="0"/>
<s:TextInput id="orderNumber" width="100"/>
</s:HGroup>
<mx:AdvancedDataGrid id="myADG"
dataProvider="{dpHierarchy}"
variableRowHeight="true" wordWrap="true">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="name" headerText="Name"/>
<mx:AdvancedDataGridColumn dataField="address" headerText="Address"/>
<mx:AdvancedDataGridColumn dataField="contact" headerText="Contact"/>
<mx:AdvancedDataGridColumn dataField="orders" headerText="Orders" itemRenderer="OrderItemRenderer"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:VBox>
</s:Application>
Item Reenderer Name: - OrderItemRenderer
<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true" width="90%" height="90%">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var initDG:ArrayCollection = new ArrayCollection();
override public function set data(value:Object):void
{
super.data = value;
initDG = new ArrayCollection(value.orders)
}
]]>
</fx:Script>
<mx:DataGrid id="dataGrid" dataProvider="{initDG}" headerHeight="0" rowCount="{initDG.length}"/>
</s:MXAdvancedDataGridItemRenderer>

How to show tool tip in mx Datagrid Row in Flex?

I want to know how i show the tool tip of each data grid row or show some specific column's data in tool tip.
If you have a DataGrid and you want to display row specific data on mouseOver, here is how this can be done.
The first step is to enable showDataTips property for every DataGridColumn that you want to enable this functionality on.
Secondly, you need to have a dataTipFunction function on the DataGrid itself. Because dataTipFunction passes over the Grid row data as an Object to the calling function, you dont need to pass any arguments to it. Here is a little example that shows how to do it.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="doInit();">
<mx:Script>
<!![CDATA[
import mx.collections.ArrayCollection; // this holds the grid data
[Bindable]
private var myData:ArrayCollection = new ArrayCollection();
private function doInit():void {
myData.addItem({fname:"Joe",lname:"Bloggs"});
myData.addItem({fname:"Joe1",lname:"Bloggs"});
}
private function buildToolTip(item:Object):String {
var myString:String = "";
if(item != null) {
myString = myString + "Firstname : " + item.fname + "\n";
myString = myString + "Lastname : " + item.lname + "\n";
}
return myString;
}
]]>
</mx:Script>
<mx:DataGrid id="dGrid" dataProvider="{myData}" visible="true" dataTipFunction="buildToolTip">
<mx:columns>
<mx:DataGridColumn dataField="fname" headerText="FirstName" showDataTips="true" />
<mx:DataGridColumn dataField="lname" headerText="LastName" showDataTips="true" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
Source: http://www.anujgakhar.com/2008/01/13/flex-how-to-have-tooltip-on-every-row-of-datagrid/
Here's another explanation from a different source:
I used the itemRollOver and the itemRollOut events.
in the itemRollOver we find the value of the object in the row, we get the label of the object and we set it as the datagrid tooltip.
itemRollOut behaves as a cleaner...
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridItemRenderer;
import mx.events.ListEvent;
import mx.controls.ToolTip;
private function createToolTip(event:ListEvent):void {
var str:String = DataGridItemRenderer(event.itemRenderer).data.label;
dataGrid.toolTip = str;
}
private function deleteToolTip(obj:Object):void {
dataGrid.toolTip = null;
}
]]>
</mx:Script>
<mx:ArrayCollection id="arrColl">
<mx:source>
<mx:Array>
<mx:Object label="Student A" score="85" />
<mx:Object label="Student B" score="48" />
<mx:Object label="Student C" score="71" />
<mx:Object label="Student D" score="88" />
<mx:Object label="Student E" score="24" />
<mx:Object label="Student F" score="64" />
</mx:Array>
</mx:source>
</mx:ArrayCollection>
<mx:DataGrid id="dataGrid"
dataProvider="{arrColl}"
itemRollOut="deleteToolTip(event)"
itemRollOver="createToolTip(event)"
>
<mx:columns>
<mx:DataGridColumn dataField="label" />
<mx:DataGridColumn dataField="score" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
Source: http://www.flexdeveloper.eu/forums/mxml/tooltip-on-datagrid-row/
-Hope that helps
Adding to Aarons answer, if you want to ONLY show tooltips when the text is longer than the column width then you can use this code (based on the roll over events example):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="plain">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridItemRenderer;
import mx.events.ListEvent;
import mx.controls.ToolTip;
private function createToolTip(event:ListEvent):void {
if (event.itemRenderer.measuredWidth>event.itemRenderer.width) {
var str:String = DataGridItemRenderer(event.itemRenderer).data.label;
dataGrid.toolTip = str;
}
}
private function deleteToolTip(obj:Object):void {
dataGrid.toolTip = null;
}
]]>
</mx:Script>
<mx:ArrayCollection id="arrColl">
<mx:source>
<mx:Array>
<mx:Object label="Student A" score="85" />
<mx:Object label="Student B" score="48" />
<mx:Object label="Student C" score="71" />
<mx:Object label="Student D" score="88" />
<mx:Object label="Student E" score="24" />
<mx:Object label="Student F" score="64" />
</mx:Array>
</mx:source>
</mx:ArrayCollection>
<mx:DataGrid id="dataGrid"
dataProvider="{arrColl}"
itemRollOut="deleteToolTip(event)"
itemRollOver="createToolTip(event)"
>
<mx:columns>
<mx:DataGridColumn dataField="label" />
<mx:DataGridColumn dataField="score" />
</mx:columns>
</mx:DataGrid>
</mx:Application>