Bom pessoal estou desenvolvendo o algoritmo de cadeias de markov pra calculo entre matrizes e teria que posuir uma datagrid redimensionavel na minha tela, o usuario informa o numero de colunas e linhas e ckica no botao de ok e a tabela tem q alto redimensionar em tempo de execução alguem sabe como fazer isso?
para as colunas pode fazer assim:
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import spark.components.gridClasses.GridColumn;
public var numeroColunas:Number;
[Bindable]
public var providerColunas:ArrayCollection = new ArrayCollection();
protected function btnOK_clickHandler(event:MouseEvent):void
{
numeroColunas = Number(txtNumeroColunas.text);
for(var i:int = 0; i <= numeroColunas; i++){
var column:GridColumn = new GridColumn();
column.headerText = "Coluna"+i;
providerColunas.addItem(column);
}
dg.columns = providerColunas;
dg.visible = true;
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:TextInput id="txtNumeroColunas"/>
<s:Button id="btnOK" label="OK" click="btnOK_clickHandler(event)"/>
<s:DataGrid id="dg" width="100%" height="100%" visible="false"/>
Cara na linha 26 ai do codigo que vc posto no meu da um erro do flex por referencia a um objeto nulo saberia pq?
protected function gerarTabela(event:MouseEvent):void
{
var col : int = txt2.text as int;
var linhas : int = txt1.text as int;
for(var i : int = 0; i < col; i++){
var coluna :GridColumn = new GridColumn();
coluna.headerText = "col" + (i+1);
colunasArray.addItem(coluna);
}
grid.columns = colunasArray;
currentState = "tabela";
}
seguinte, sem ver o restante do código não dá pra saber com certeza, mas imagino que seu grid, esteja em outro state sem ser o tabela, ai quando vc vai acessar ele para passar o provider das colunas, ele ainda está nulo…pq só depois vc muda de state.
è vc estava certo mas a respeito do state mas a tabela esta ficando sem nenhuma coluna vou postar o codigo pra vc dar uma olhada
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.dataGridClasses.DataGridColumn;
import spark.components.gridClasses.GridColumn;
[Bindable] public var lista : ArrayCollection = new ArrayCollection();
[Bindable] public var colunasArray : ArrayCollection = new ArrayCollection();
protected function init() : void
{
}
protected function gerarTabela(event:MouseEvent):void
{
var col : int = txt2.text as int;
var linhas : int = txt1.text as int;
for(var i : int = 0; i >< col; i++){
var coluna :GridColumn = new GridColumn();
coluna.headerText = "col" + (i+1);
coluna.width = 50;
colunasArray.addItem(coluna);
}
currentState = "tabela";
grid.columns = colunasArray;
}
]]>
</fx:Script>
<s:states>
<s:State name="definicao"/>
<s:State name="tabela"/>
</s:states>
<s:DataGrid includeIn="tabela" id="grid" x="22" y="10" width="300" height="200"/>
<mx:VBox includeIn="definicao" horizontalAlign="center" verticalAlign="middle" width="100%" height="100%">
<mx:Canvas y="264" width="60%" height="72">
<s:Button id="gerar" x="346" y="25" label="Ok" click="gerarTabela(event)"/>
<s:Label id="lb1" x="56" y="34" text="Linhas:"/>
<s:Label id="lb2" x="202" y="34" text="Colunas:"/>
<s:TextInput id="txt1" x="106" y="24" width="74"/>
<s:TextInput id="txt2" x="261" y="24" width="67"/>
</mx:Canvas>
</mx:VBox>
</s:WindowedApplication>
o erro ta no seu
for(var i : int = 0; i >< col; i++)
" i >< col" faz assim “i <= col”