Search the web
Sign In
New User? Sign Up
flexcoders · RIA Development with Adobe Flex
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
This is not as easy as it seems ... apparently...   Message List  
Reply | Forward Message #145327 of 149594 |
Re: This is not as easy as it seems ... apparently...

I GIVE UP!! I have tried everything!!.. I have a dataGrid that binds to
an ArrayCollection. I need to change the value of one columen (Profit)
based on the value of another column (Kind) ie.. the results (either
'LONG' or SHORT'). Here is where I'm at. I've tried putting code into
customer DataGridColumns and labelFunctions and ItemRenderers... but can
not do it. What seem to be working most are events in the DataGrid
Component, better than others, but comparing values in a DataGrid is
obviously impossible.

Somehow I need the code to access ArrayCollection getItemat() but I
can't do it!

Please help!

<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="initTA()">

<positions:KindColumn id="Kind"
headerText="Kind"
dataField="Kind"
itemRenderer="com.steury.baseClasses.CellFieldTrd"/>
<positions:ProfitColumn id="Profit"
headerText="Profit"/>

<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import com.steury.baseClasses.*;
import mx.core.Application;
import mx.controls.dataGridClasses.DataGridListData;
import flash.events.Event;
import mx.core.ClassFactory;
import com.steury.controls.positions.*;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.DataGrid;

private function initTA():String {
if (value[Kind.dataField]=="LONG")Profit.dataField="Profit";
if
(value[Kind.dataField]=="SHORT")Profit.dataField="ShProfit";
Profit.itemRenderer=new
ClassFactory(com.steury.baseClasses.CellFieldInt);
return myDec.format(Profit)+"%";
}








--- In flexcoders@yahoogroups.com, "Craig" <craigj@...> wrote:
>
> I am trying to access the value of a DataGridColumn and change the
> DataField for another column based on this value...
> Here is my code:
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
> creationComplete="getDp()" >
>
> ... Datagrid>
> <mx:columns>
> <mx:DataGridColumn dataField="Ticker"
> headerText="Ticker"/>
> <mx:DataGridColumn id="Kind"
> dataField="Kind"
> itemRenderer="com.steury.baseClasses.CellFieldTrd" />
> <mx:DataGridColumn id="Profit"
> headerText="Profit"/>
>
> ActionScript:
>
> private function getDp():void {
>
if(Application.application.CnvPos.dgOrdExt.selectedItem.Kind=="LONG")Pro\
\
>
fit.dataField="Profit";Application.application.CnvPos.dgOrdExt.refresh()\
\
> ;
> }
>
>
> //This code works find if I use
>
> if(Kind.DataField="Kind")Profit.dataField="Profit";
>
> //above to test the rest of the code.
>
> I can not figure out how to access the value of the Datagridcolumn. I
> have tied using event listeners, etc.. which did not work. Please let
> me know if anyone can help this fairly simple dilemma.
>





Sun Jul 12, 2009 9:49 pm

cjsteury2
Offline Offline
Send Email Send Email

Forward
Message #145327 of 149594 |
Expand Messages Author Sort by Date

I am trying to access the value of a DataGridColumn and change the DataField for another column based on this value... Here is my code: <?xml version="1.0"...
Craig
cjsteury2
Offline Send Email
Jul 11, 2009
5:57 pm

I GIVE UP!! I have tried everything!!.. I have a dataGrid that binds to an ArrayCollection. I need to change the value of one columen (Profit) based on the...
Craig
cjsteury2
Offline Send Email
Jul 12, 2009
9:50 pm

You access the value in a column of a datagrid like this... yourDataGrid.selectedItem["dataColumnNameOfColumn"]...
postwick
Offline Send Email
Jul 13, 2009
12:01 am

I am trying to set the value of a column based on the value of another column. If I use ...selectedItem... it does not work, unless I am mistaken....
Craig
cjsteury2
Offline Send Email
Jul 13, 2009
2:35 am

Is the datagrid bound to a collection? if so, change the value in the collection. or try... yourDataGrid.selectedItem["dataColumn1"] =...
postwick
Offline Send Email
Jul 13, 2009
2:51 am

yes the datagrid is bound to an array collection. I don't want to select any item, I want to change the value of a column's DataField to a one of two values...
Craig
cjsteury2
Offline Send Email
Jul 13, 2009
3:05 am

if you just did dataGrid.selectedItem then that would be the selected row. add ["columnname"] to get to the column, so: dataGrid.selectedItem["columnname"] ...
postwick
Offline Send Email
Jul 13, 2009
3:10 am

so if it's doing it row by row, then it would need to be a labelfunction event right? where would you suggest the code go? there needs to be an if...
Craig
cjsteury2
Offline Send Email
Jul 13, 2009
3:18 am

From within the custom component DataGrid Column I tried this code as you suggested at the initialize event but it errors: ...
Craig
cjsteury2
Offline Send Email
Jul 13, 2009
3:12 am

Is there a particular row you want to update? If a row is selected, you would use... Profit.selectedItem["datafieldname"]...
postwick
Offline Send Email
Jul 13, 2009
3:16 am

Not sure why you have all the Application.application stuff on there. Just reference the datagrid by it's id. <mx:DataGrid id="mygrid"....> ...
postwick
Offline Send Email
Jul 13, 2009
3:17 am

cause I was doing it within the custom component (column) itself for the datagrid, which can not hold an Id value, I can put it in the parent component...
Craig
cjsteury2
Offline Send Email
Jul 13, 2009
3:19 am

Ok... In the parent component to the datagrid I used an initialize event: public function initDg():void { ...
Craig
cjsteury2
Offline Send Email
Jul 13, 2009
3:31 am

You can't use selectedItem because there is no selectedItem. You haven't clicked a row. Try looping through the grid. In the end, I really don't understand...
postwick
Offline Send Email
Jul 13, 2009
3:35 am

now we're getting somewhere! but will this update the value of the col2 or the value of col2 DataField? I am trying to change the value of col2 DataField to...
Craig
cjsteury2
Offline Send Email
Jul 13, 2009
3:49 am

That'll update the value of the cell. You can't do what you're trying to do. You can't have a column with a different dataField per row. The dataField for...
postwick
Offline Send Email
Jul 13, 2009
3:52 am

... thank you, sir... I appreciate your help, I shall do as you say !! Craig...
Craig
cjsteury2
Offline Send Email
Jul 13, 2009
3:58 am

First, to make it completely clear, when working with the data, you must always use the underlying dataProvider and item and never the DataGrid or cell itself....
Tracy Spratt
nts333rd
Offline Send Email
Jul 13, 2009
12:49 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help