tags:

views:

228

answers:

4

I use an item renderer to display a checkbox in my datagrid like;

<mx:DataGridColumn headerText="Visible" dataField="visibleInd" width="48" 
itemRenderer="mx.controls.CheckBox" 
rendererIsEditor="true" 
editorDataField="selected"
/>

And that works fine, but the checkbox is aligned left like;

alt text

How can I align it in the middle?

I have used;

            <mx:DataGridColumn headerText="Visible" dataField="visibleInd" width="48" 
                               editorDataField="selected"
                               >
            <mx:itemRenderer>
                <fx:Component>
                    <mx:Box width="100%" height="100%" 
                            horizontalAlign="center" verticalAlign="middle">
                        <mx:CheckBox selected="{data.visibleInd}" />
                    </mx:Box>
                </fx:Component>
            </mx:itemRenderer>

But in this case my code does align the checkbox in the middle, but does not save data in my dataprovider.

Am I missing something?

A: 

I'm pretty sure this will work by changing mx:itemRenderer to mx:itemEditor.

Wade Mueller
+1  A: 

Instead of using <mx:Box />, use <mx:Canvas /> or <s:Group /> (in Flex 4)

Also, set the horizontalCenter="0" on the checkbox.

ie:

       <mx:itemRenderer>
            <fx:Component>
                <mx:Canvas width="100%" height="100%">
                    <mx:CheckBox selected="{data.visibleInd}" horizontalCenter="0" />
                </mx:Canvas>
            </fx:Component>
        </mx:itemRenderer>
Marty Pitt
A: 

try making checkbox width to 100%

Treby
+1  A: 

Simply use DataGridColumn's textAlign Style:

<mx:DataGridColumn headerText="Visible" textAlign="center">
    <mx:itemRenderer>
        <mx:Component>
            <mx:CheckBox selected="{data.visibleInd}"/>
        </mx:Component>
    </mx:itemRenderer>
</mx:DataGridColumn>
splash