Welcome, Guest. Please login or register.
Did you miss your activation email?
05/23/12, 02:23
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  V2 Components (Flash MX 2004 - Flash 8) (Moderators: vesa kortelainen, Ronald Wernecke, Jorge Solis, ..:: Mazhar Hasan ::.., papachan)
| | |-+  How to get the value from a ComboBox within a datagrid ?
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: How to get the value from a ComboBox within a datagrid ?  (Read 4476 times)
Dick Chong
Server what's that
*
Posts: 30



View Profile Email
« on: 05/05/04, 10:17 »

I have followed the tutorial and added a ComboBox component in a datagrid successfully.  The next thing I try to do is to get the value from the ComboBox component.  So, I have tried to setup some listener events such as cellPress and cellEdit in order to capture the data of the selected item in the combo box.  

However, all my efforts were failed... I can only get the result in my output window like "NaN" or "undefined" or "object:ojbect:ojbect".

Actually, what I want to do is to fill something in another column when I choose something in the combo box... Is it possible to do this within a datagrid ?

Please give me some advice. Thanks a lot for any helping hand !

Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #1 on: 05/05/04, 11:06 »

Hi Dick,
if you insert a combo into a datagrid, the path to it is pretty long, thats it:

datagridName.selectedItem["columnName"].comboboxName.selectedItem.value should do it Wink

But dont nail me on that Wink it is right out of my mind and not tested Wink

If you want to find out where you are, try to put a trace(this) into the code.

Usualy you'll get the full path back, if not, try it with trace(_parent); to receive the container.
Logged

happy flashing
Cool
Ronald
Dick Chong
Server what's that
*
Posts: 30



View Profile Email
« Reply #2 on: 05/05/04, 21:15 »

Thanks for your suggestion, I have tried it but it returns "undefined".  I am quite sure about which kind of listener should I use if I want to listen to the change event of the embedded combo box. I have tried "cellEdit" and "cellPress" but not succeed.

Thanks again for any helping hands.
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #3 on: 05/06/04, 00:39 »

Hi Dick,
this is not the question of the event handler, it is rather one of the path to the data.

Each component you add, needs an instance name, and therwith adds its path to it.

This looks complicated, but if you know the structure of your application, you can address everything from everywhere.

Thry to find out which position you are by using _parent, or _parent._parent, until you know where you are. Then you will find the way to the right field inside of the component.
Logged

happy flashing
Cool
Ronald
Dick Chong
Server what's that
*
Posts: 30



View Profile Email
« Reply #4 on: 05/06/04, 11:16 »

thanks a lot for your advice, Ronald.

I think I do not understand where should I place the "trace" in order to find the path of my combo box.  Below is my code, please help me to figure it out... thanks a lot...

import mx.controls.gridclasses.DataGridColumn;

var column = new DataGridColumn("Code");
column.headerText = "Code";
column.width=100;
column.cellRenderer = "ComboBoxCellRenderer";
test_dg.addColumn(column);

var column = new DataGridColumn("Price");
column.headerText = "Price";
column.width=100;
test_dg.addColumn(column);

var column = new DataGridColumn("Quantity");
column.headerText = "Quantity";
column.width=100;
test_dg.addColumn(column);

var column = new DataGridColumn("Amounts");
column.headerText = "Amounts";
column.width=200;
test_dg.addColumn(column);

test_dg.resizableColumns = false;

data_array = new Array();
data_array.push({Code:[{label:"100-0", data:"100-0"}, {label:"100-8", data:"100-8"}, {label:"100-10", data:"100-10"}], Price:"", Quantity:"", Amount:""});

test_dg.dataProvider = data_array;

multiply = new Object();
multiply.cellEdit = function(evt){
   var row = evt.target.selectedIndex
   var p = Number(evt.target.selectedItem.Price)
   var q = Number(evt.target.selectedItem.Quantity)
   var amt = p*q
   test_dg.editField(row, "Amounts", amt)
}
test_dg.addEventListener("cellEdit", multiply);
Logged
Matt
Server what's that
*
Posts: 23



View Profile Email
« Reply #5 on: 05/06/04, 19:30 »

try opening the class file (should be in your folder com/flash-db/ComboBoxCellRenderer.as )

you should see:
Code:
function change()   
   {
      //Refresh the dataProvider and save value in ModelName and
      //ModelVal columns for later retrieve
      listOwner.dataProvider.editField(getCellIndex().itemIndex, getDataLabel(), reorder(combo.dataProvider, combo.selectedItem.label));
      listOwner.dataProvider.editField(getCellIndex().itemIndex, getDataLabel()+"Name", combo.selectedItem.label);      
      listOwner.dataProvider.editField(getCellIndex().itemIndex, getDataLabel()+"Val", combo.selectedItem.data);            
   }

change it to look like that:

Code:
function change()   
   {

trace(this); //will provide you the path for the value
_root.cbSelected_value=combo.selectedItem.data; //give an easy value name/path for the value
trace(_root.cbSelected_value); //will trace the value
      //Refresh the dataProvider and save value in ModelName and
      //ModelVal columns for later retrieve
      listOwner.dataProvider.editField(getCellIndex().itemIndex, getDataLabel(), reorder(combo.dataProvider, combo.selectedItem.label));
      listOwner.dataProvider.editField(getCellIndex().itemIndex, getDataLabel()+"Name", combo.selectedItem.label);      
      listOwner.dataProvider.editField(getCellIndex().itemIndex, getDataLabel()+"Val", combo.selectedItem.data);            
   }

I didn't try the code but I guess it should be working.

Good Luck

Matt
« Last Edit: 05/06/04, 19:32 by Matt » Logged
Matt
Server what's that
*
Posts: 23



View Profile Email
« Reply #6 on: 05/06/04, 19:40 »

also the proper way to get a value from the datagrid is this one:

_root.test_dg.myDatagrid.getItemAt(_root.rowSelected).Code

to get _root.rowSelected add this code:

Code:

var myListener = new Object(); //create new listener
myListener.cellPress = function(event) { //when a cell is pressed
_root.rowSelected=event.itemIndex;//give a value to the selected Row
};
test_dg.addEventListener("cellPress", myListener);


Also as you are looking at a combobox you may have to try _root.test_dg.myDatagrid.getItemAt(_root.rowSelected).Code.label or _root.test_dg.myDatagrid.getItemAt(_root.rowSelected).Code.data
Logged
Dick Chong
Server what's that
*
Posts: 30



View Profile Email
« Reply #7 on: 05/06/04, 21:32 »

Hi, Matt

I have add a trace(_parent) into the class file and I get the result like this "_level0.test_dg.content_mc.listRow10".  I don't understand why there is a "content_mc" in the path since the instance name of the combo box is "Combo".  Also do you know what is the meaning of listRow10 ?  I have created only three items in the combo box and there is only one row in my datagrid.

Besides, I found that the combo box inside the datagrid did not respond to the "cellPress" event.  It only respond to event defined in the class file "ComboBoxCellRenderer".  Any idea on this issue ?

Thanks a lot for your helps...

Dick
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!