I have a datagrid where users put in different numbers for 3 different columns. These values are then calculated after the user puts in each value for each column. I also have a combobox component inside my datagrid. What I want this combobox to do is perform a different mathematical formula based on what the user selects. For example, in the combobox if the user selects 'Long'(the first option in the combobox) it performs Column1*(col2-Col3)-col4=total column or if t开发者_如何学Gohe user selects 'Short'(the second option in the combobox) it performs col1*(Col3-col2)+column4=total column. How would I do that? I've tried different ideas none which have seemed to work so any examples or suggestions would be greatly appreciated.
public function getTotal(item:Object, column:DataGridColumn):String
{
switch(comboBox)
{
case "Long":
var sum:int = item.quantity*(item.exit-item.entry)-item.commission;
return currencyFormatter.format(sum);
case "Short":
sum = item.quantity*(item.entry-item.exit)-item.commission;
return currencyFormatter.format(sum);
}
}
I took the idea that you gave me and used parameters for the function but like I said before I keep running into error 1170. I get that it is saying my function is not returning a value but I dont understand why? Any clarification is more than welcome.
Your question is a bit confusing. How can a user "put in different values" that "are then calculated" Users do not usually input calculated values!
That said, it sounds like you need a big switch statement to calculate the values.
switch(comboBox.selectedItem)
{
case ""ong":
calculatedValue = Column1*(col2-Col3)-col4;
break;
case "Short":
calculatedValue = col1*(Col3-col2)+column4;
break;
}
I assume all the values displayed in your DataGrid relate to a specific object created for that row. You can put your calculate function in the renderer for your caluclated column and reference those items of your object's dataProvider directly:
switch(data['comboBoxSelectedItem'])
{
case ""ong":
data['calculatedValue'] = data['Column1Value']*(data['col2Value']-data['Col3Value'])-data['col4Value'];
break;
case "Short":
data['calculatedValue'] = data['col1Value']*(data['Col3Value']-data['col2Value'])+data['column4Value'];
break;
}
精彩评论