Creating a column of RadioButtons in Adobe Flex - flex3

I am having an un-predictable behavior of creating radio buttons in advancedDataGrid column using itemRenderer. Similar kind of problem has been reported at
Creating a column of RadioButtons in Adobe Flex. I tried to use the same procedure i.e. bind every radio button selectedValue and value attributes with the property specified in the property of the associated bean but still facing the problem.
The button change values! The selected
button becomes deselected, and
unselected ones become selected.
Here is the code of my advancedDataGrid:
<mx:AdvancedDataGrid id="adDataGrid_rptdata"
width="100%" height="100%"
dragEnabled="false" sortableColumns="false"
treeColumn="{action}"
liveScrolling="false"
displayItemsExpanded="true" >
<mx:dataProvider>
<mx:HierarchicalData source="{this.competenceCollection}" childrenField="competenceCriteria"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn headerText="" id="action" dataField="criteriaName" />
<mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">
<mx:RadioButton name="period1" value="{data}" selected="{data.period1}" group="{data.radioBtnGrpArray[0]}" visible="{data.showRadioButton}" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
<mx:AdvancedDataGridColumn headerText="Periode 2" dataField="" width="200">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">
<mx:RadioButton name="period2" value="{data}" selected="{data.period2}" group="{data.radioBtnGrpArray[1]}" visible="{data.showRadioButton}" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
<mx:AdvancedDataGridColumn headerText="Periode 3" dataField="" width="200">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">
<mx:RadioButton name="period3" value="{data}" selected="{data.period3}" group="{data.radioBtnGrpArray[2]}" visible="{data.showRadioButton}" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
</mx:columns>
</mx:AdvancedDataGrid>
Any work around is highly appreciated in this regard!

The selected button becomes deselected, and unselected ones become selected.
Is this problem occurring only for those radio buttons whose selected state was manually changed by the user? In that case it is because flex resets its selected state based on the value mentioned in the declaration when a RadioButton is reused. So even if you select/deselect a ratio button in the Periode 1 column, flex resets it to {data.period1} when you scroll away and come back. Making the column editable to save the modifications back to the data provider might work. Try changing the column declaration to:
<mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200"
editable="true" rendererIsEditor="true" editorDataField="selected">
EDIT: Try this - attempting to change the data provider when the radio button is selected. code written from memory and not tested - might contain bugs.
<mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" width="100%"
verticalAlign="middle">
<mx:RadioButton id="rb" name="period1" value="{data}"
selected="{data.period1}"
group="{data.radioBtnGrpArray[0]}" visible="{data.showRadioButton}"
change="outerDocument.handleRadio1(this);"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
//in a script tag outside the datagrid.
public function handleRadio1(renderer:IListItemRenderer):void
{
var index:Number = adDataGrid_rptdata.itemRendererToIndex(renderer);
this.competenceCollection[i].period1 = renderer.rb.selected;
}

Related

How i fill combobox items in Radgridview manually using in vb.net

How I fill combobox items in Radgridview manually without using datasource in vb.net I have a Radgridview in my form.(radgridview1) radgridview1 contained 3 Column and column number 3 is combobox type. I want to fill each combobox in column 3 with this data using code: UNP IPE Angle BOX Other Profile. I don't know how to do it.
You can use GridTemplateColumn like the following.
<telerik:GridTemplateColumn ItemStyle-Wrap="true" ItemStyle-VerticalAlign="Middle"
ItemStyle-HorizontalAlign="center" AllowFiltering="false" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Width="3%" ItemStyle-Width="3%" HeaderText="Profile">
<ItemTemplate>
<telerik:RadComboBox>
<Items>
<telerik:RadComboBoxItem Text="UNP" Value="UNP" />
<telerik:RadComboBoxItem Text="IPE" Value="IPE" />
<telerik:RadComboBoxItem Text="ANGLE" Value="ANGLE" />
<telerik:RadComboBoxItem Text="BOX" Value="BOX" />
<telerik:RadComboBoxItem Text="Other Profile" Value="OTHER" />
</Items>
</telerik:RadComboBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
or else you can bind each comboBox in _ItemDataBound

vb.net datatype in manually added column

Dim pctofpax As New DataColumn
pctofpax = New DataColumn("PCTPAX1", GetType(Decimal))
pctofpax.Expression = "[ASOFPAX] / [YEPAX]"
ds.Tables("workplease").Columns.Add(pctofpax)
Dim avgppax As New DataColumn
avgppax = New DataColumn("AVG PAX", GetType(Double))
avgppax.Expression = "[Current Sales] / [Current PAX]"
ds.Tables("workplease").Columns.Add(avgppax)
These are two columns that i added into my asp.net/vb.net datagrid. the problem is i keep trying to change the datatypes so they show up as numbers with only two decimals but it is not working
<span lang="en-us">Sales As Of Analysis</span><br />
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
<asp:BoundColumn DataField="PCTPAX1"
HeaderText="PCTPAX1"
DataFormatString="{0:c}">
</div>
</form>
</body>
</html>
and nothing happend to my data
If it's just a matter of displaying only two decimals, this can be accomplished in the display code for the DataGrid:
<asp:BoundField DataField="PCTPAX1"
HeaderText="PCTPAX1"
DataFormatString="{0:c}">
Note the DataFormatString value of {0:c} which specifies that the formatting of the value in that field should be "currency." (You can also try with a capital C, I don't have a test handy for it right now.) There's a lot more you can do with format strings, more information here.
Or do you want the actual values to be rounded to currency values? You'll likely use Math.Round for that, though I don't have an example handy. There's information about that here.
Edit: Based on your comment(s), it sounds like you were attempting to change data types at the database level. This won't really impact the code. The value coming back from the database in the form of a double or decimal or some other numeric likely won't carry that precision back to the code. As far as the DataGrid is concerned, it's calling .ToString() on a double and showing the result. No database data type is involved. Using the DataFormatString property to pass a format string to the .ToString() method is how to change the display.
Edit again based on your question edit: Your HTML is broken. You have the BoundColumn outside of the grid, and the column tag itself isn't closed. Columns go inside the grid. See the grid layout here. Basically, you'd want something more like:
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:BoundField DataField="PCTPAX1"
HeaderText="PCTPAX1"
DataFormatString="{0:c}">
</asp:BoundField>
</Columns>
</asp:GridView>
Changing the type of a column which is already in your datatable doesn't work. or at least not that i know. if you just want to get a different formatting, look at the answers above.

Problems with XUL Grid Layout

I'm working on creating an XUL app right now and I'm stuck with a few problems at this point. My current file is here: http://projects.thecloudonline.net/gemxul/regrid.xul.
I want that second column to essentially "float: right" (like how CSS works on webpages). The red background shows me that part moved, but my content is stuck oriented left. How can I make the content go along with it?
Secondly, my overall goal is to get it so that the layout is essentially split in half. Setting maxwidth="50%" on the first column doesn't seem to do anything. Is that the correct approach, or am I way off there?
That's all for now!
This should work :
<grid style="border: #000000 solid 1px;">
<columns>
<column style="border-right: #666666 solid 1px;"/>
<column flex="1"/>
<column style="background-color:red;"/>
</columns>
<rows>
<row>
<vbox>
<label value="Launcher 1" id="l1_title"/>
<button label="button" id="l1_btn" />
<label value="This is a description for item 1." id="l1_desc"/>
</vbox>
<spacer/>
<vbox>
<label value="Launcher 2" id="l2_title"/>
<button label="button" id="l2_btn"/>
<label value="This is a description for item 2." id="l2_desc"/>
</vbox>
</row>
<row style="border-top: #666666 solid 1px;">
<vbox>
<label value="Launcher 3" id="l3_title"/>
<button label="button" id="l3_btn"/>
<label value="This is a description for item 3." id="l3_desc"/>
</vbox>
<spacer/>
<vbox>
<label value="Launcher 4" id="l4_title"/>
<button label="button" id="l4_btn"/>
<label value="This is a description for item 4." id="l4_desc"/>
</vbox>
</row>
</rows>
</grid>
There are several ways of doing this. Personally I wouldn't use grid for something like this. vbox and hbox in combination beats anything you would normally do in tables. But of course it depends entirely what your end goal is.

Flex List Component with Checkbox

I am trying to add a checkbox to a List component in my application and everything works seeming well until I scroll through my data.
As I scroll vertically in my List, any checks I may have added start to get added to other items in my List, sometimes the original item I checked is not even checked anymore.
For example, my List height is enough to see 5 items, I check Item 1, scroll down and every 5th item starts to get checked.
It's really odd and I have not been able to figure out why it is doing this. I looked at some examples online, and I'm not doing anything any different as far as I can tell.
I ran some traces and the Checkbox datachange event fires as I scroll through my list, but again, I am not sure why.
Here is the mxml test page for my List.
Any help is appreciated, thanks.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Array id="arr">
<mx:Object label="One" />
<mx:Object label="Two" />
<mx:Object label="Three" />
<mx:Object label="Four" />
<mx:Object label="Five" />
<mx:Object label="Six" />
<mx:Object label="Seven" />
<mx:Object label="Eight"/>
<mx:Object label="Nine" />
<mx:Object label="Ten" />
<mx:Object label="Eleven" />
<mx:Object label="Twelve" />
</mx:Array>
<mx:List
id="addrList"
height="100"
width="100%" fontSize="10"
borderStyle="solid"
borderColor="#000000"
borderThickness="1"
dataProvider="{ arr }">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox
change="trace('change')"
dataChange="trace('dataChange')"/>
</mx:Component>
</mx:itemRenderer>
</mx:List>
</mx:Application>
your putting an object to a list dataprovider, dataprovider supports text only
try this
<mx:Script>
<![CDATA[
[Bindable]
private var arr:Array = ["a","b","c","d","e","f","g"];
]]>
</mx:Script>
<mx:List
id="addrList"
height="100"
width="100%" fontSize="10"
borderStyle="solid"
borderColor="#000000"
borderThickness="1"
dataProvider="{ arr }">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox change="trace('change')"
dataChange="trace('dataChange')"/>
</mx:Component>
</mx:itemRenderer>
</mx:List>

drop in an HBox

I have this HBox with drop functionality:
SCRIPT:
// The dragEnter event handler for the HBox container enables dropping.
private function dragEnterHandler(event:DragEvent):void
{
if (!event.dragSource.hasFormat("items"))
return;
var dropTarget:Box = Box(event.currentTarget);
dropTarget.setStyle("borderStyle", "outset");
DragManager.acceptDragDrop(dropTarget);
DragManager.showFeedback(DragManager.MOVE);
}
private function dragExitHandler(event:DragEvent):void
{
if (!event.dragSource.hasFormat("items"))
return;
var dropTarget:Box = Box(event.currentTarget);
dropTarget.setStyle("borderStyle", "inset");
}
MXML
<mx:HBox id="invoiceHBox" borderStyle="inset" borderThickness="3"
height="40" width="260"
dragEnter="{dragEnterHandler(event);}"
dragExit="{dragExitHandler(event);}"
dragDrop="{dragDropHandler(event);}">
<mx:VBox>
<mx:Image source="{MailIcon32}" visible="{Boolean(invoiceEmail)}" />
<mx:Label text="{invoiceEmail.name}" styleName="heading4" />
<mx:Text text="{invoiceEmail.description}"
width="100%" selectable="false" />
</mx:VBox>
</mx:HBox>
When the mouse enters the HBox, it works fine. The data can be dropped into the HBox and the function dragDropHandler (a very long function) does its work.
However, when the mouse hovers over the VBox, the drop functionality is lost. Can the VBox container somehow inherit from the HBox? or is there another solution to this problem?
thanks!
You need to disable the mouseChildren property of the HBox and it should work
<mx:HBox id="invoiceHBox" borderStyle="inset" borderThickness="3"
height="40" width="260"
dragEnter="{dragEnterHandler(event);}"
dragExit="{dragExitHandler(event);}"
dragDrop="{dragDropHandler(event);}"
mouseChildren="false" >
<mx:VBox>
<mx:Image source="{MailIcon32}" visible="{Boolean(invoiceEmail)}" />
<mx:Label text="{invoiceEmail.name}" styleName="heading4" />
<mx:Text text="{invoiceEmail.description}"
width="100%" selectable="false" />
</mx:VBox>
</mx:HBox>