0

我很快就在一周内解决一个问题,但我仍然无法按预期工作。我有一个 DataGrid,它有一个 HBox 和一个 CheckBox 和一个标签作为 itemRenderer(参见下面的代码)。当我点击单元格时,标准 itemEditor 会弹出并让您输入标签的内容。那是标准行为。我工作正常,除了 2 个问题:

  1. 如果我输入太多文本,水平滚动条会弹出,并且单元格会充满该滚动条。如您所见,我尝试将 Horizo​​ntalScrollPolicy 设置为关闭,但这根本不起作用......我尝试对所有不同的元素执行此操作,但故障仍然存在。

  2. 当我填写了多行时,会发生另一个错误。如果我点击一行,数据网格会选择该行下方的那个。仅当已经选择了一行时。如果我在数据网格外部点击,然后在任何一行点击右行的 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;

      }               
 }
}

提前致谢!马库斯

4

2 回答 2

0
  • 为了避免滚动条,您必须让数据网格具有可变高度

<mx:DataGrid id="dg"
 dataProvider="{dp}"
 variableRowHeight="true" 
 creationComplete="dg.height=dg.measureHeightOfItems(0,dp.length)+dg.headerHeight+2"/>
于 2010-03-15T15:46:51.783 回答
0
  • I am not sure if this is the reason behind your issues, but the standard way of creating children is to override the createChildren method.

  • Also, you are missing an else statement - you are not calling super.data when if condition fails. That doesn't look good either.

Try:

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
    }
  }
}
于 2010-03-15T12:58:07.683 回答