|
That works perfectly! I'll let the code slide, since it's
my first flex project :)
Thanks again!
Shan
Shannon,
Usually we have intermediary "UI Library" that solves most of such issues
via extended set of props/styles (as you probably noticed with OnValue/offValue
extensions on the sample). For brevity, I am just going to center it always -
with code I am going to hate in the morning:
package com.theriabook.controls { import
mx.controls.CheckBox; import
mx.controls.dataGridClasses.DataGridListData; import
mx.core.mx_internal;
use namespace mx_internal;
public class CheckBox extends mx.controls.CheckBox
{ mx_internal override function
layoutContents(unscaledWidth:Number,
unscaledHeight:Number,
offset:Boolean):void {
super.layoutContents(unscaledWidth, unscaledHeight,
offset); currentIcon.x = unscaledWidth/2 -
5; }
public var onValue:Object = "1"; public var
offValue:Object = "0"; public function set value(o:Object) :void
{ selected = (o ==
onValue); } public function get
value():Object { return
selected?onValue:offValue; }
override public function set
data(item:Object):void { super.data =
""> if( item!=null ) value =
item[DataGridListData(listData).dataField]; }
} }
Regards,
Anatole
On 7/14/06, Shannon
Hicks <[EMAIL PROTECTED]>
wrote:
Heh... so,
I used your class that extends the CheckBox, and functionally it works great.
Unfortunately, it's still not centered, and I'm still not sure how to
accomplish it.
I did try
to use an inline itemRenderer, and put a HBox around it (centered)... which
centered the custom checkbox class, but then it threw the same error as
before...
ReferenceError: Error #1069:
Property selected not found on flexComponents.editMouse_inlineComponent1 and
there is no default value.
So... how do I center
an extended checkbox? :)
Shan
Jason,
Well, I looked at your sample and it got me confused - I am sure Flex
will be confused too. For one, on binding, you need to specify _expression_ that
would convert selected into 1|0 like selected?1:0.
Here is what I suggest to do to figure out the problem. Compile you app
with -keep-generated-actionscript=true. Take a look @ 3 (guessing) files
generated for your inline component. Read the code, see all the binding
happening there along with overhead related to extra container and think
again.
Please review my posting again. Using class without container gives you
what you want - in simple transparent way
package com.theriabook.controls
{
import
mx.controls.CheckBox;
import
mx.controls.dataGridClasses.DataGridListData;
public
class CheckBox extends mx.controls.CheckBox
{
public var onValue:Object = 1;
public var offValue:Object = 0;
public function set value(o:Object) :void {
selected = (o == onValue);
}
public function get value():Object
{
return selected?onValue:offValue;
}
override public function set data(item:Object):void
{
super.data = "">
if( item!=null )
value = item[DataGridListData(listData).dataField];
}
}
}
and these attributes on the datagridcolumn
...
itemRenderer="com.theriabook.controls.CheckBox"
rendererIsEditor="true"
editorDataField="value"> If you think
you would not be able to reuse CheckBox class or would like in place
definition in the same file please consider code above nevertheless and use
className on component tag so the implementation is clean and it is easy to
refactor when the code review / second generation of developers come
Sincerely,
Anatole
On 7/14/06, Pan
Troglodytes <
[EMAIL PROTECTED]> wrote:
Anatole:
You seem pretty knowledgable about Flex. Can you
find any problem with the casting approach I posted? Seems like a bit
less of a hassle than defining an external class.
On 7/14/06, Anatole
Tartakovsky <
[EMAIL PROTECTED]> wrote:
You can use this class as your item renderer
package com.theriabook.controls
{
import mx.controls.CheckBox;
import
mx.controls.dataGridClasses.DataGridListData;
public class CheckBox extends mx.controls.CheckBox
{
public var onValue:Object = 1;
public var offValue:Object = 0;
public function set value(o:Object) :void {
selected = (o == onValue);
}
public function get value():Object
{
return selected?onValue:offValue;
}
override public function set data(item:Object):void
{
super.data = "">
if( item!=null )
value =
item[DataGridListData(listData).dataField];
}
}
}
and these attributes on the datagridcolumn
...
itemRenderer="com.theriabook.controls.CheckBox"
rendererIsEditor="true"
editorDataField="value">
Styling and dealing with settings
controls defaults without drop-in itemRenderer requires subclassing of
DataGridColumn and it's ClassFactory - described in details in
upcoming Flex book, but would take about 5 pages to explain. Nevertheless,
the case is "classical, will try to respond via components forum
Thank you,
Anatole
On 7/14/06, Shannon
Hicks < [EMAIL PROTECTED]>
wrote:
Pan-
I
tried this, and the checkbox shows up properly
checked/unchecked.
Now,
I get this error when I change the state:
ReferenceError: Error #1069: Property selected not found on
flexComponents.editMouse_inlineComponent1 and there is no default
value.
Shan
Flash knows how to convert 0/1 to Boolean, it just doesn't always
know WHEN to do it. To answer both your questions, here is a
modified version of the help example:
<?xml version="1.0"?> <mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml" height="700"
width="700">
<mx:Script> <![CDATA[
[Bindable] public var
myDP:Array = [
{label1:"Order #2314", contact:"John Doe", quant:3, solddate:new
Date(2005, 0, 1), Sent:1},
{label1:"Order #2315", contact:"Jane Doe", quant:3, solddate:new
Date(2005, 0, 5), Sent:0}]; ]]>
</mx:Script>
<mx:DataGrid id="myDG" dataProvider="{myDP}"
variableRowHeight="true" width="500" height="250" editable="true">
<mx:columns>
<mx:DataGridColumn
dataField="label1"
headerText="Order #" editable="false"/>
<mx:DataGridColumn
dataField="quant"
headerText="Quantity"
itemEditor="mx.controls.NumericStepper
"
editorDataField="value"/>
<mx:DataGridColumn
dataField="solddate"
headerText="Date"
itemRenderer="
mx.controls.DateField"
rendererIsEditor="true"
editorDataField="selectedDate"/>
<mx:DataGridColumn dataField="Sent" rendererIsEditor="true"
editorDataField="selected" textAlign="center">
<mx:itemRenderer>
<mx:Component>
<mx:Canvas width="100%" height="100%">
<mx:CheckBox selected="{Boolean(data.Sent)}" horizontalCenter="0"
verticalCenter="0"/>
</mx:Canvas>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn> </mx:columns>
</mx:DataGrid> </mx:Application>
On 7/14/06, Shannon Hicks < [EMAIL PROTECTED]>
wrote:
I have a dataGrid where I'd like to
use a checkbox drop-in renderer/editor. My query returns two columns:
name [varchar(45)] and featured [smallint]. Featured returns
either 1 or 0.
Now, in the dataGrid, my featured
column looks like this:
<mx:DataGridColumn
headerText="Featured Image" dataField="featured"
itemRenderer="mx.controls.CheckBox" rendererIsEditor="true"
editorDataField="selected" textAlign="center"/>
First off... The checkbox doesn't
show checked/unchecked according to the value of featured (1 or 0). Do
I need to somehow convert 1 & 0 to boolean values? Isn't flash
supposed to do this automatically?
Secondly... The checkbox isn't
centered. I'm not sure how to do that, as silly as it
sounds.
Shan
-- No virus found in this outgoing
message. Checked by AVG Free Edition. Version: 7.1.394 / Virus
Database: 268.10.0/388 - Release Date: 7/13/2006
-- Jason
-- No virus found in this incoming
message.
Checked by AVG Free Edition. Version: 7.1.394 / Virus
Database: 268.10.0/388 - Release Date: 7/13/2006
-- No virus found in this outgoing
message. Checked by AVG Free Edition. Version: 7.1.394 / Virus
Database: 268.10.0/388 - Release Date:
7/13/2006
-- No virus found in this incoming message. Checked by
AVG Free Edition. Version: 7.1.394 / Virus Database: 268.10.0/388 - Release
Date: 7/13/2006
-- No virus found in this outgoing message. Checked by
AVG Free Edition. Version: 7.1.394 / Virus Database: 268.10.0/388 - Release
Date: 7/13/2006
-- No virus found in this incoming message. Checked by AVG
Free Edition. Version: 7.1.394 / Virus Database: 268.10.0/388 - Release Date:
7/13/2006
__._,_.___
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
YAHOO! GROUPS LINKS
__,_._,___
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.0/388 - Release Date: 7/13/2006
|