PDA

View Full Version : AdvancedDataGrid: binding and selecting cells


dominik.glodzik
08-06-2008, 09:13 AM
Hello

I am having problems with setting a cell of my AdvancedDataGrid as selected.

An XMLListCollection serves as a data provider for the ADG. When I feed data into the XMLListCollection, it correctly appears in the table. However, when I try to highlight a cell in the table, the data disappears.

he problem doesn't occur if I assign data to the XMLListCollection twice.

To replicate this, first click on the "Load button". It loads data into the XMLListCollection. Then click "change selection", which should highlight the cell (0,0).
Not that if you hit "Load" twice, the problem doesn't happen.

I would appreciate help or even a small hint.;)



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

<mx:Script>
<![CDATA[
import mx.controls.advancedDataGridClasses.AdvancedDataGr idBaseSelectionData;
import mx.controls.advancedDataGridClasses.AdvancedDataGr idBase;
import mx.collections.XMLListCollection;


var dominikData : XML = <data>
<c> <a>1</a> <b>2</b> <d>3</d> </c>
<c> <a>4</a> <b>5</b> <d>6</d> </c>
<c> <a>7</a> <b>8</b> <d>9</d> </c>
</data>;

[Bindable]
private var tableXML : XMLListCollection;

public function fetchGraphData() : void {
tableXML = new XMLListCollection(dominikData.children());
}


private function changeSelection(x : int, z : int) : void {
var temp : Array = dg.selectedCells;
temp = [{ rowIndex : x, columnIndex : z }];
dg.selectedCells=temp;
}


private function itemsSelected(event:Event):void {
}


]]>
</mx:Script>



<mx:AdvancedDataGrid id="dg"
allowMultipleSelection="true" selectionMode="singleCell" itemClick="itemsSelected(event)"
fontSize="10" rowHeight="14" columnWidth="10" paddingBottom="0" dataProvider="{tableXML}"
paddingLeft="0" paddingRight="0" paddingTop="0" x="10" y="550" width="1200" height="300" sortableColumns="false" draggableColumns="false">

<mx:columns>
<mx:AdvancedDataGridColumn id="a" dataField="a" />
<mx:AdvancedDataGridColumn id="b" dataField="b"/>
<mx:AdvancedDataGridColumn id="d" dataField="d"/>
</mx:columns>
</mx:AdvancedDataGrid>


<mx:Button x="240" y="233" label="Change selection" click="changeSelection(0,0);"/>
<mx:Button x="240" y="300" label="Load" click="{fetchGraphData();}"/>

</mx:Application>

dominik.glodzik
08-06-2008, 09:24 AM
Also, I can't use dg.invalidateList() every time I select a cell, because it is slow when there is more data.

With the little example it works though.

Dominik