如何:AS3 中自定义 DataGridColumn ItemRenderer 中的 RadioButton

发布于 2024-08-30 13:30:44 字数 711 浏览 1 评论 0原文

我有一个数据网格,我想使用 AS3 (而不是 mxml)添加一列单选按钮。我可以使用自定义 itemRenderer 来做到这一点。

var dgc:DataGridColumn = new DataGridColumn();
dgc.itemRenderer = new ClassFactory(com.mypackage.RadioBtnColumnItemRenderer);

在我的 RadioBtnColumnItemRenderer.mxml 中,我有一个带有 radioButton 的框...如下所示:

<?xml version="1.0" encoding="utf-8"?>
<mx:Box 
xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center" verticalAlign="middle"
>
<mx:RadioButton id="btnRadio"
   groupName="btnRadioSelect"
/>
</mx:Box>

当我运行应用程序时,单选按钮按其应有的方式显示在列中。但是,我无法仅选择其中一个单选按钮。我可以选择所有这些,但我不想要这个...我想要选择一个的能力,然后如果我选择另一个,那么第一个将被取消选择,当前的将被选中(就像您会期望单选按钮能够工作)。

我缺少什么?

I have a datagrid that I want to add a column of radio button using AS3 (instead of mxml). I was able to do this with a custom itemRenderer.

var dgc:DataGridColumn = new DataGridColumn();
dgc.itemRenderer = new ClassFactory(com.mypackage.RadioBtnColumnItemRenderer);

In my RadioBtnColumnItemRenderer.mxml, I have a box with a radioButton... like so:

<?xml version="1.0" encoding="utf-8"?>
<mx:Box 
xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center" verticalAlign="middle"
>
<mx:RadioButton id="btnRadio"
   groupName="btnRadioSelect"
/>
</mx:Box>

When I run the application, the radio button shows up in the column as it should. However, I cannot select just ONE of the radio buttons. I am able to select all of them, but I don't want this... I want the ability to select one, and then if I select another one, then the first one is unselected and the current one becomes selected (just like you would expect radio buttons to work).

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

究竟谁懂我的在乎 2024-09-06 13:30:44

你实际上很接近。您只需使用“properties”属性将对组的引用传递到类工厂中。

var dgc:DataGridColumn = new DataGridColumn();
var ir: = new ClassFactory(com.mypackage.RadioBtnColumnItemRenderer);
var radioGroup:RadioButtonGroup = new RadioButtonGroup(this);
ir.properties = {radioGroup:radioGroup}; //THIS IS KEY
dgc.itemRenderer = ir;

现在,在渲染器中,您需要在类似这样的地方设置该属性。

<mx:Script>
    [Bindable]
    public var radioGroup:RadioButtonGroup; 
</mx:Script>
<mx:RadioButton id="btnRadio"  group="{radioGroup}"  />

You're actually pretty close. You just need to pass the reference to the group into the class factory using the "properties" property.

var dgc:DataGridColumn = new DataGridColumn();
var ir: = new ClassFactory(com.mypackage.RadioBtnColumnItemRenderer);
var radioGroup:RadioButtonGroup = new RadioButtonGroup(this);
ir.properties = {radioGroup:radioGroup}; //THIS IS KEY
dgc.itemRenderer = ir;

Now in the renderer you need that property set somewhere like this.

<mx:Script>
    [Bindable]
    public var radioGroup:RadioButtonGroup; 
</mx:Script>
<mx:RadioButton id="btnRadio"  group="{radioGroup}"  />
謌踐踏愛綪 2024-09-06 13:30:44

您需要定义一个 RadioButtonGroup 才能使其仅选择一种行为。我认为如果您将此组放入项目渲染器中,您将无法实现所需的行为,因此您可能需要找到一种方法来从保存数据网格的容器中引用该组。

http://livedocs.adobe.com/flex/3/ langref/mx/controls/RadioButtonGroup.html

You'll need to define a RadioButtonGroup to have this select only one behavior. I think if you put this group in the item renderer, you won't be able to achieve the desired behavior though, so you may need to figure out a way to reference the group from the container holding the data grid.

http://livedocs.adobe.com/flex/3/langref/mx/controls/RadioButtonGroup.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文