Example of how to use itemeditbegin and itemeditbegin In the flex DataGrid to verify the input of a positive floating point number

Source: Internet
Author: User

<? XML version = "1.0"?>

<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml">

<Mx: SCRIPT>

<! [CDATA [

Import MX. utils. stringutil;

Import MX. Controls. textinput;

Import MX. Events. Maid;

Import MX. Events. datagridevent;

Import MX. Controls. numericstepper;

Import MX. Collections. arraycollection;

Import MX. Controls. listclasses. idropinlistitemrenderer;

[Bindable]

Private var mydp: arraycollection = new arraycollection ([

{ARTIST: 'pavement ', album: 'slanted and enchanted', price: 11.99 },

{ARTIST: 'pavement ', album: 'crooked rain, crooked rain', price: 10.99 },

{ARTIST: 'pavement ', album: 'wowee zowee', price: 12.99 },

{ARTIST: 'pavement ', album: 'brighten the corn', price: 11.99 },

{ARTIST: 'pavement ', album: 'terror twilight', price: 11.99}

]);

// Verify the validity of the input data

Private function validateitem (Event: datagridevent): void {

// Return directly if no data is updated

If (event. Reason = maid. cancelled ){

Return;

}

VaR input: textinput = textinput (_ grid. itemeditorinstance );

VaR newdata: String = textinput (event. currenttarget. itemeditorinstance). text;

If (event. datafield = "price "){

VaR pattern: Regexp =/(0 + /. [0-9] * [1-9] {1,}) | ([1-9] [0-9] */. /d) | ([1-9] *) $ /;

Newdata = pattern.exe C (newdata) [0];

If (stringutil. Trim (newdata). Length <= 0 ){

Event. preventdefault ();

Input. errorstring = "The number format is incorrect! ";

Return;

}

}

}

// If the number is input, only numbers and decimal places can be entered in the input box.

Private function doitemeditbegin (Event: datagridevent): void {

VaR colname: String = _ grid. Columns [event. columnindex]. datafield;

If (colname = "price "){

_ Grid. createitemeditor (event. columnindex, event. rowindex );

_ Grid. itemeditorinstance. Data = _ grid. editeditemrenderer. Data;

Textinput (_ grid. itemeditorinstance). Restrict = "0-9 /.";

}

}

]>

</MX: SCRIPT>

<Mx: DataGrid id = "_ grid" dataprovider = "{mydp }"

Editable = "true"

Itemeditbegin = "doitemeditbegin (event );"

Itemeditend = "validateitem (event )"

>

<Mx: columns>

<Mx: datagridcolumn datafield = "artist"/>

<Mx: datagridcolumn datafield = "album" width = "130"/>

<Mx: datagridcolumn datafield = "price"/>

</MX: columns>

</MX: DataGrid>

</MX: Application>

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.