Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to bind internal data to Flex DataGrid components

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to bind internal data to Flex DataGrid components, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

Display a list of data using the Flex DataGrid component

Displaying data list is the most basic application of Flex DataGrid component. Only by displaying the data can other functions be realized. There are probably two sources of data, one is internal data, which is customized within the program and then bound to the Flex DataGrid component, and the other is external data, which is bound to the Flex DataGrid component by reading external files or databases. Next, we will introduce these two situations respectively.

Bind internal data to a Flex DataGrid component

To display data in a Flex DataGrid component, you must first establish a data source, which is usually achieved through the DataProviderAPI class. The following example shows how to display data in a Flex DataGrid component, with the following steps.

Step 1 of ◆: create an ActionScript3.0 file named DataGrid_ShowData_Example.as and the class DataGrid_ShowData_Example, and import the class library that will be used. The code is as follows:

Package {importfl.controls.DataGrid; importfl.controls.ScrollPolicy; importfl.data.DataProvider; importflash.display.Sprite; publicclassDataGrid_ShowData_ExampleextendsSprite {/ * constructor * * / publicfunctionDataGrid_ShowData_Example () {}

◆ step 2: create a function GetData1 to implement the specific function internally. The code is as follows:

/ * load internal data, bind Flex DataGrid component * * / privatefunctionGetData1 (): void {}

Step 3 of ◆; inside the function, create a data model with 4 columns and 10 rows of data using the DataProvider class. The code is as follows:

/ / data model

Vardp1:DataProvider=newDataProvider (); dp1.addItem ({Name: "Tom", Phone:23579086,QQ:77788899,Software: "Flash"}); dp1.addItem ({Name: "Kelly", Phone:33579080,QQ:56788823,Software: "Flex"}); dp1.addItem ({Name: "Jim", Phone:83579085,QQ:56788882,Software: "Java"}); dp1.addItem ({Name: "Sam", Phone:73579084,QQ:78988811,Software: "Dreamweaver"}) Dp1.addItem ({Name: "Kaiven", Phone:33576681,QQ:32188897,Software: "Photoshop"}); dp1.addItem ({Name: "Gray", Phone:23229086,QQ:12388900,Software: "Fireworks"}); dp1.addItem ({Name: "Luar", Phone:23579087,QQ:24681899,Software: "DAEMONTools"}); dp1.addItem ({Name: "Kite", Phone:85579082,QQ:68080894,Software: "FlashDevelop"}) Dp1.addItem ({Name: "Polar", Phone:32579086,QQ:21586899,Software: "BeyondCompare"})

◆ step 4: initialize the Flex DataGrid component, instantiate it, and then set the properties, including position, width, height, scroll bar style, and so on. The code is as follows:

/ / initialize the Flex DataGrid component and instantiate vardg1:DataGrid=newDataGrid (); / / set the location dg1.move (200.20); / / set the width and height dg1.setSize (350150); dg1.verticalScrollPolicy=ScrollPolicy.AUTO

◆ step 5: define the column title, then bind the data model to the Flex DataGrid component and put it on the stage, the code is as follows:

/ / define column headings dg1.columns= ["Name", "Phone", "QQ", "Software"]; / / bind data source dg1.dataProvider=dp1; addChild (dg1)

Step 6 of ◆; compile the code and run it.

Thank you for reading this article carefully. I hope the article "how to bind internal data to Flex DataGrid components" shared by the editor will be helpful to you. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report