数据网格在我的数据网格中选择了错误的自定义单元格 [英] Datagrid selects the wrong custom cell in my datagrid

查看:16
本文介绍了数据网格在我的数据网格中选择了错误的自定义单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一周后我正在解决一个问题,但我仍然无法使其按预期工作.我有一个 DataGrid,它有一个带有 CheckBox 和一个标签的 HBox 作为 itemRenderer(见下面的代码).当我点击 Cell 时,标准 itemEditor 会弹出并让您输入标签的内容.那是标准行为.除了两个问题,我工作正常:

  1. 如果我输入了很多文本,水平滚动条就会弹出,并且单元格被那个滚动条填满.正如你所看到的,我试图将水平滚动策略设置为关闭,但这根本不起作用......我试图为所有不同的元素这样做,但失败仍然存在.

  2. 当我填写了不止一行时,发生了另一个错误.如果我点击一行,数据网格会选择该行下方的一个.只有在已经选择了一行的情况下.如果我点击数据网格外部,然后点击任意行,右行的 itemEditor 将显示...现在我的设置数据方法的设置中是否有任何问题?

__

打包组件{导入 mx.containers.HBox;导入 mx.controls.CheckBox;导入 mx.controls.Label;公共类 ChoiceRenderer 扩展了 HBox{私有变量正确答案:复选框;私有变量选择标签:标签;公共函数 ChoiceRenderer(){极好的();画();}私有函数paint():void{百分比高度 = 100;百分比宽度 = 100;setStyle("horizo​​ntalScrollPolicy", "off");super.setStyle("horizo​​ntalScrollPolicy", "off");正确答案 = 新复选框;rightAnswer.setStyle("horizo​​ntalScrollPolicy", "off");addChild(正确答案);选择标签 = 新标签;choiceLabel.setStyle("horizo​​ntalScrollPolicy", "off");添加孩子(选择标签);}覆盖公共函数集数据(xmldata:Object):void{if(xmldata.name() == "BackSide"){var xmlText:Object = xmldata.TextElements.TextElement.(@position == position)[0];super.data = xmlText;choiceLabel.text = xmlText.toString();rightAnswer.selected = xmlText.@correct_answer;}}}

提前致谢!马库斯

解决方案

  • 为了避免滚动条,你必须让数据网格具有可变高度
<前><代码><mx:DataGrid id="dg"数据提供者="{dp}"variableRowHeight="true"creationComplete="dg.height=dg.measureHeightOfItems(0,dp.length)+dg.headerHeight+2"/>

I am working on a problem since a week soon, but I still couldn't make it work as expected. I have a DataGrid which has HBox with a CheckBox an a Label as itemRenderer (see Code below). When I tap in to the Cell the standard itemEditor pops up and lets you enter the content of the label. Thats the standard behavior. I works fine except for 2 problems:

  1. If I enter to much text, the horizontal srollbar pops up, and the cell is filled with that scrollbar. As you see I tried to set the horizontalScrollPolicy to off, but that doesnt work at all... I tried to do that for all the different elements, but the failure is still existent.

  2. When I have filled more than one row, there is an other mistake happening. If I tap on a row, the datagrid selects the one below that row. That's only if one line is already selected. If I tap outside the datagrid and then, tap at any row the itemEditor of the right row will show up... Is there anything now wright in the setup of my set data method?

__

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;

      }               
 }
}

Thanks in advance! Markus

解决方案

  • in order to avoid scroll bar you have to let datagrid have variable height


<mx:DataGrid id="dg"
 dataProvider="{dp}"
 variableRowHeight="true" 
 creationComplete="dg.height=dg.measureHeightOfItems(0,dp.length)+dg.headerHeight+2"/>

这篇关于数据网格在我的数据网格中选择了错误的自定义单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆