Flex4.6 DataGrid customizing ComboBox and getting Values for custom combobox

Source: Internet
Author: User

Recently, project requirements need to dynamically generate GridColumn on the DataGrid and set it as a ComboBox, which by default is TextInput.

Flex 4.6 uses S:datagrid components instead of Mx:datagrid, and many of the online materials are MX components, so this article is written.


First, the S:datagrid title bar stores objects that are gridcolumn.

Title bar dynamic Add function

<span style= "Font-family:microsoft yahei;font-size:18px;" >var columnspro:gridcolumn = new GridColumn (); columnspro.headertext = Headertext;columnspro.datafield = DataField; Columnspro.width = 80;contentgrid.columns.additem (Columnspro);</span>
here Contentgrid is the ID number of your DataGrid

Sets the Itemrenderer property that is used to gridcolumn the custom control.

First, create a new Mxml component, called Pointsymbol, which has the following code

<span style= "Font-family:microsoft yahei;font-size:18px;" ><?xml version= "1.0" encoding= "Utf-8"? ><s:griditemrenderer xmlns:fx= "http://ns.adobe.com/mxml/2009" xmlns:s= "Library://ns.adobe.com/flex/spark" xmlns:mx= "library://ns.adobe.com/flex/mx" width= "" height= "> <fx:script><span style= "White-space:pre" ></span></fx:Script><fx:Declarations>  <!--Place non-visual elements (such as services, value objects) here--  </fx:Declarations>  <s:layout>  <s: Horizontallayout verticalalign= "Middle" horizontalalign= "center"/>  </s:layout>  <!--<s:i Mage source= "{data.datafield4}"/>--><mx:combobox id= "ComBo" width= "" height= "change=" Pointrankchange (Event) "/> </s:GridItemRenderer></span>
Initialize display of ComboBox values requires overloaded methods

<span style= "Font-family:microsoft yahei;font-size:18px;" >override Public Function set data (value:object): Void{super.data = value; Combo.dataprovider = Pointlabel; Combo.selectedindex = Getarraycollectionindex (Pointlabel,value.rank);} </span>
here getarraycollectionindex is my own definition of the method, you can not consider, value is your incoming object, you can define your own ComboBox display to how many positions, Pointlabel is the ArrayCollection object that I define.

When the ComboBox changes, you need to store the changed values in your main interface, you need to use the Dispatchevent event

<span style= "Font-family:microsoft yahei;font-size:18px;" >protected function Pointrankchange (event:listevent): void{//TODO auto-generated method Stubvar myevent:listevent = New Listevent ("Pointchange"); Myevent.reason = Combo.selectedlabel;this.parentapplication.dispatchevent (myEvent);} </span>
Here Combo is the ID number of the ComboBox.


The method is monitored in the main interface and the Itemrender is set to the current custom control.

<span style= "Font-family:microsoft yahei;font-size:18px;" >comboboxfactory = new ClassFactory (pointsymbol); AddEventListener ("Pointchange", Comboboxchange);</span>
then
<span style= "Font-family:microsoft yahei;font-size:18px;" >columnspro.itemrenderer = comboboxfactory;</span>

In the main interface. Mxml, the replication method Comboboxchange.

<span style= "Font-family:microsoft yahei;font-size:18px;" >var Item:object=contentgrid.selecteditem;var Index:int=contentgrid.dataprovider.getitemindex (item); var Item:O Bject = contentGrid.dataProvider.getItemAt (index); if (Event.type = = "Pointchange") {Item.rank = Event.reason;} </span>
<span style= "WHITE-SPACE:PRE; BACKGROUND-COLOR:RGB (240, 240, 240); " ><span style= "Font-family:microsoft yahei;font-size:18px;" >contentgrid.dataprovider.setitemat (Item,index);</span></span>
for the sake of convenience, I saved the value in the Event.reason attribute.


The above is the DataGrid custom ComboBox and gets its value, of course, the rest of the custom control can be.




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Flex4.6 DataGrid customizing ComboBox and getting Values for custom combobox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.