473,503 Members | 3,045 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Flex xmllist to datagrid into a single row

16 New Member
I have made a lot of datagrids work in my time, but I seem to be missing something.

I'm receiving an xmllist and all I'm trying to do is set the dataprovider. It should be straight forward, but it's placing all the children of '<userName>someName</userName>' into a single row.

Here's the xmllist that I'm receiving:
Expand|Select|Wrap|Line Numbers
  1. <users><userName>rob</userName>
  2. <userName>testd3</userName>
  3. <userName>mickey</userName>
  4. <userName>john</userName>
  5. <userName>kip</userName>
  6. <userName>pauly</userName></users>
  7.  
Here's the AS3 code receiving the xmllist and setting a provider:
Expand|Select|Wrap|Line Numbers
  1.             private function gotUsersOfGroups(x:XMLList):void
  2.             {
  3.                 var myString:String = '<users>';
  4.                 myString += x.children().child("userName");
  5.                 myString += '</users>';
  6.                 trace(myString);
  7.                 var myXml:XML = new XML(myString);
  8.  
  9.                 myUserList.dataProvider = myXml;
  10.             }            
  11.  
Pretty simple, right? I've tried myXml.userName, myXml.children(), myXml.children.child("userName") and nothing seems to work.

What am I missing?

As usual, thanx n advance
Oct 24 '08 #1
2 9998
kronus
16 New Member
I figured it out and it was something simple. I had to send my XML to an XMLListCollection. I renamed the variables so that the code could be easy to follow. And I had to take out the Datagrid columns section of the mxml

Expand|Select|Wrap|Line Numbers
  1.             private function gotUsersOfGroups(x:XMLList):void
  2.             {
  3.                 var xmlListString:String = '<users>';
  4.                 xmlListString += x.children().child("userName");
  5.                 xmlListString += '</users>';
  6.                 var convertUserStringToXml:XML = new XML(xmlListString);
  7.                 var usersOfGroupsXmlListCol:XMLListCollection = new XMLListCollection(convertUserStringToXml.userName);
  8.  
  9.  
  10.                 myUserList.dataProvider = usersOfGroupsXmlListCol;
  11.                 trace(usersOfGroupsXmlListCol);
  12.             }
  13.  
  14.             <mx:DataGrid id="myUserList" height="100%" width="65%" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true" styleName="blueContainer1" backgroundColor="#2C4054" color="#FFFFFF" />
  15.  
But now, I cannot name the column header. How do I do that without bringing back the datagrid columns?

Thanx n advance
Oct 24 '08 #2
kronus
16 New Member
I was able to use the labelFunction for the datagridcolumn to populate the datagridcolumn, along with the use of the headerText to give my column a header.

First, the new mxml
Expand|Select|Wrap|Line Numbers
  1.         <mx:DataGrid id="myUserList" height="100%" width="65%" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true" styleName="blueContainer1" backgroundColor="#2C4054" color="#FFFFFF">
  2.             <mx:columns>
  3.                 <mx:DataGridColumn headerText="Users" labelFunction="usersOfGroupLabelFunction" />
  4.             </mx:columns>
  5.  
  6.         </mx:DataGrid>
  7.  
And the two functions that make it possible for me to have my cake and eat it too:
Expand|Select|Wrap|Line Numbers
  1.             private function gotUsersOfGroups(x:XMLList):void
  2.             {
  3.                 var xmlListString:String = '<Users>';
  4.                 xmlListString += x.children().child("userName");
  5.                 xmlListString += '</Users>';
  6.                 trace(xmlListString);
  7.                 var convertUserStringToXml:XMLList = new XMLList(xmlListString);
  8.                 var usersOfGroupsXmlListCol:XMLListCollection = new XMLListCollection(convertUserStringToXml);
  9.  
  10.                 var sortA:Sort = new Sort();
  11.                 sortA.fields= [new SortField(null, true)];
  12.                 usersOfGroupsXmlListCol.sort=sortA;
  13.                 usersOfGroupsXmlListCol.refresh();
  14.  
  15.                 myUserList.dataProvider = usersOfGroupsXmlListCol.child("userName").valueOf();
  16.                 myUserList.validateNow();
  17.             }
  18.  
  19.             private function usersOfGroupLabelFunction(item:Object, uogDataGridCol:DataGridColumn):String
  20.             {
  21.                 return item.text();
  22.             }
  23.  
Two things:
1) Since this particular xml data was different in construct than all the other xml data that I was retrieving, then I had to treat it differently. Namely in that the other xml data had <sometag name="something" /> but this one was <sometag>something</sometag> and apparently my Flex 3 no longer likes item.valueOf but item.text worked just fine. Go figure?
2) I threw in a Sort function that I found somewhere on the net while trying to figure this out and I knew that if the sort function was working, then I had a true XMLListCollection.

Thanx 4 giving me a sounding board
Oct 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3594
by: Peter Kleiweg | last post by:
Hi, I am looking for a Python equivalent of Flex. After some browsing, it seems that Plex is my best bet, but I would like to hear suggestions before I dive in. I have been using Flex a lot...
2
6564
by: olig9 | last post by:
Hello, is there a way to feed an ifstream to a parser generated with flex and bison? I could see that flex wants a FILE* for reading, but I only have an ifstream (actually and ifstream*) for...
2
13985
by: Qumer Mumtaz | last post by:
H How to us MS Flex Grid in C#.I mean how to add columns and rows at run time and how to assign values to the columns and rows ? Any help in this regard will be appriciated Plz reply sooon............
9
10735
by: Vincent | last post by:
I am trying to create a function that is called on the Flex Grid's MouseDown event. However, this event is not listed in the properties for this object. I tried to manually create the prototype...
5
5932
by: ASP.NET explorer | last post by:
I have been asked to create some simple animation using Adobe Flash player in ASP.NET(C#) web application. While I am fairly well versed with ASP.NET C#, I absolutely have NO IDEA about how to...
10
6685
by: Jules Winfield | last post by:
Guys, I've been designing applications for the financial services industry using MSFT technologies for many years (Win32 API, MFC, and now .NET WinForms). All applications are Internet-based,...
3
3518
by: Tarik Monem | last post by:
Hi Everyone, Still a newbie with FLEX, and I've passed arrays using AJAX to FLEX before, but I've never passed links to FLEX. Basically, this is the OUTPUT, which I wanted, but I'm given an...
3
8617
by: kronus | last post by:
Hi Everyone, It's been a long time and I'm always appreciative of your help. I'm working on a Datagrid at the component level in Flex. I know that I can expand a row within the Datagrid by...
0
2283
by: bhappy | last post by:
Hi, I am using Flex 3.0 version. Can anyboday have any idea about showing hand symbol on mouseover of any cell in datagrid? Please provide me any sample code or links. Thanks in Advance,...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.