Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-26-2007, 10:21 PM   #1
vlad2005
Member
 
Join Date: Apr 2005
Posts: 94
Default binding between dataGrid and comboBox

I have an dataGrid with some columns, and an comboBox with values from one column that is in my dataGrid. When i change value in dataGrid, i want to change and values in my combo too. For that need some bindings, but i dont know how.
vlad2005 is offline   Reply With Quote
Old 06-26-2007, 11:38 PM   #2
drkstr
Flexpert
 
drkstr's Avatar
 
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587
Default

Maybe someone has a cleaner solution, but I would just listen for a change event on the data grid, then update the combo box to your DataGrid.selectedItem (or whichever data is supposed to populate the combo box).

Best regards,
...aaron
drkstr is offline   Reply With Quote
Old 06-27-2007, 07:10 AM   #3
vlad2005
Member
 
Join Date: Apr 2005
Posts: 94
Default

This is easy, but i want that all data show into one column in dataGrid to be show and in comboBox, not only selectedItem.
vlad2005 is offline   Reply With Quote
Old 06-27-2007, 04:48 PM   #4
drkstr
Flexpert
 
drkstr's Avatar
 
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587
Default

Oh I see what your saying now. DataGrid.columns[x] should get what you need.

hope this helps,
...aaron
drkstr is offline   Reply With Quote
Old 06-27-2007, 06:59 PM   #5
vlad2005
Member
 
Join Date: Apr 2005
Posts: 94
Default

can be more specific?
I have an combo box named myCb. How i can populate with dataGrid.columns[x]
vlad2005 is offline   Reply With Quote
Old 06-28-2007, 07:43 AM   #6
drkstr
Flexpert
 
drkstr's Avatar
 
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587
Default

Uh, well it's impossible to tell you the exact implementation to use without knowing the specific needs of your program. But from what it sounds like, you have data in a column you want to use in a ComboBox. The DataGrid.columns property returns an array of columns, so pick which column from that array you want to pull data from, then assign it to the dataProvider of the combo box. I assume you know how to take it from there since you said this was easy.

Best regards,
...aaron
drkstr is offline   Reply With Quote
Old 06-28-2007, 09:52 AM   #7
vlad2005
Member
 
Join Date: Apr 2005
Posts: 94
Default

i try'it myCb.dataProvider = myDG.columns[0];
but not work. Any idea?
vlad2005 is offline   Reply With Quote
Old 06-28-2007, 06:45 PM   #8
drkstr
Flexpert
 
drkstr's Avatar
 
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587
Default

My apologize, I forgot the columns property returns a display object, not the data itself. Since a DataGrid lists it's data by row and not columns, you may need to do something like this:

Code:
<?xml version="1.0"?>
<!-- DataGrid control example. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
<![CDATA[

import mx.collections.ArrayCollection;

[Bindable]
private var myCBDataProvider:ArrayCollection;

private function updateComboBox(): void {
	var columnData:ArrayCollection = new ArrayCollection();
	
	for each( var row:Object in idDataGrid.dataProvider ) {
		columnData.addItem(row.name.toString());
	}
	
	myCBDataProvider = columnData;
}
	
]]>
</mx:Script>

    <mx:XMLList id="idEmployees">
        <employee>
            <name>Christina Coenraets</name>
            <phone>555-219-2270</phone>
            <email>[email protected]</email>
            <active>true</active>
        </employee>
        <employee>
            <name>Joanne Wall</name>
            <phone>555-219-2012</phone>
            <email>[email protected]</email>
            <active>true</active>
        </employee>
        <employee>
            <name>Maurice Smith</name>
            <phone>555-219-2012</phone>
            <email>[email protected]</email>
            <active>false</active>
        </employee>
        <employee>
            <name>Mary Jones</name>
            <phone>555-219-2000</phone>
            <email>[email protected]</email>
            <active>true</active>
        </employee>
    </mx:XMLList>

    <mx:Panel title="DataGrid Example" height="100%" width="100%" 
        paddingTop="10" paddingLeft="10" paddingRight="10">

        <mx:DataGrid id="idDataGrid" width="100%" height="100%" rowCount="5" dataProvider="{idEmployees}">
            <mx:columns>
                <mx:DataGridColumn dataField="name" headerText="Name"/>
                <mx:DataGridColumn dataField="phone" headerText="Phone"/>
                <mx:DataGridColumn dataField="email" headerText="Email"/>
            </mx:columns>
        </mx:DataGrid>

		<mx:ComboBox id="idComboBox" dataProvider="{myCBDataProvider}" />
		<mx:Button label="Update ComboBox" click="updateComboBox();" />
        
    </mx:Panel>
</mx:Application>
But again, I can't tell you the exact implementation you should use without seeing the code. The best way to do it really depends on a lot of different factors.

Hope this was more of a help,
...aaron
drkstr is offline   Reply With Quote
Old 06-28-2007, 09:15 PM   #9
vlad2005
Member
 
Join Date: Apr 2005
Posts: 94
Default

Yes, that is one solution, and work well for my intention. Thanks for your time!
vlad2005 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS3] ComboBox inside Datagrid CFB001 Components 13 02-05-2009 10:18 AM
combobox and datagrid xnegvx Flex 2, 3 & 4 1 03-10-2007 05:21 PM
Combobox AMFPHP and a Datagrid orionzwei Components 3 10-30-2006 06:50 PM
combobox datagrid lose selected item himik Flex 2, 3 & 4 1 09-19-2006 09:22 PM
combobox and datagrid: how to alternate the data? tapic Components 2 07-26-2005 04:28 PM


All times are GMT. The time now is 05:39 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.