我很快就会在一周内解决问题,但我仍然无法按预期工作。我有一个DataGrid,其中HBox带有CheckBox,Label带有itemRenderer(参见下面的代码)。当我点击Cell时,弹出标准itemEditor并允许您输入标签的内容。这是标准行为。我工作正常,除了2个问题:
如果我输入了很多文本,水平滚动条会弹出,单元格会被该滚动条填充。如你所见,我试图将horizontalScrollPolicy设置为off,但这根本不起作用......我试图为所有不同的元素做到这一点,但失败仍然存在。
当我填写多行时,还会发生另一个错误。如果我点击一行,数据网格会选择该行下面的那一行。只有在选择了一行时才会这样。如果我在数据网格外部点击,然后点击右行的itemEditor将显示的任何行...现在有什么东西可以设置我的设置数据方法吗?
__
package components
{
import mx.containers.HBox;
import mx.controls.CheckBox;
import mx.controls.Label;
public class ChoiceRenderer extends HBox
{
private var correctAnswer:CheckBox;
private var choiceLabel:Label;
public function ChoiceRenderer()
{
super();
paint();
}
private function paint():void{
percentHeight = 100;
percentWidth = 100;
setStyle("horizontalScrollPolicy", "off");
super.setStyle("horizontalScrollPolicy", "off");
correctAnswer = new CheckBox;
correctAnswer.setStyle("horizontalScrollPolicy", "off");
addChild(correctAnswer);
choiceLabel = new Label;
choiceLabel.setStyle("horizontalScrollPolicy", "off");
addChild(choiceLabel);
}
override public function set data(xmldata:Object):void{
if(xmldata.name() == "BackSide"){
var xmlText:Object = xmldata.TextElements.TextElement.(@position == position)[0];
super.data = xmlText;
choiceLabel.text = xmlText.toString();
correctAnswer.selected = xmlText.@correct_answer;
}
}
}
提前致谢! 马库斯
答案 0 :(得分:0)
我不确定这是否是您的问题背后的原因,但创建子项的标准方法是覆盖createChildren
方法。
此外,您缺少else
语句 - 当super.data
条件失败时,您不会调用if
。这看起来也不好。
尝试:
package components
{
public class ChoiceRenderer extends HBox {
private var correctAnswer:CheckBox;
private var choiceLabel:Label;
public function ChoiceRenderer() {
super();
percentHeight = 100;
percentWidth = 100;
setStyle("horizontalScrollPolicy", "off");
}
override protected function createChildren():void {
super.createChildren();
correctAnswer = new CheckBox();
addChild(correctAnswer);
choiceLabel = new Label();
choiceLabel.setStyle("horizontalScrollPolicy", "off");
addChild(choiceLabel);
}
override public function set data(xmldata:Object):void {
if(xmldata.name() == "BackSide") {
var xmlText:Object = xmldata.TextElements.TextElement.(@position == position)[0];
super.data = xmlText;
choiceLabel.text = xmlText.toString();
correctAnswer.selected = xmlText.@correct_answer;
}
else {
//what if xmldata.name() is not "BackSide"?
//you are not calling super.data in that case
}
}
}
答案 1 :(得分:0)
<mx:DataGrid id="dg"
dataProvider="{dp}"
variableRowHeight="true"
creationComplete="dg.height=dg.measureHeightOfItems(0,dp.length)+dg.headerHeight+2"/>