We help IT Professionals succeed at work.

FLEX AdvancedDatagrid Column visibility

VKN9876
VKN9876 asked
on
Medium Priority
1,081 Views
Last Modified: 2012-05-06
Hi All,

I'm have a datagrid with 30 columns and trying to set the visibility on and off programatically. I want to make sure atleast one column should be visible in the datagrid (i.e. the user can set the visiblity off only on 29 columns max). How this can be done?
I tried with countColumns but always the count is returning max number of columns.

Thanks
Comment
Watch Question

Commented:
Show some of your code and we'll take a look.
zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
The class AdvancedDataGridColumn has a property visible that you can set true or false
Sr. Software engineer
CERTIFIED EXPERT
Commented:
This small app should give you quite some inspiration
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
				layout="vertical"
				verticalAlign="middle"
				backgroundColor="white"
				creationComplete="onCreationComplete()">
 
	<mx:Script>
	<![CDATA[
		import mx.controls.Alert;
		import mx.collections.ArrayCollection;
 
		[Bindable]private var arrayOfString:Array;
 
		[Bindable]
		public var dgArray:ArrayCollection = new ArrayCollection([
			{Price:'Lots', Store:'yahoo', Artist:'Jack'},
			{Price:'None', Store:'amazon', Artist:'Jill'}
		]);
		
		private function onCreationComplete():void {
			myGrid.dataProvider = dgArray;
			pChk.selected = priceColumn.visible;
			sChk.selected = storeColumn.visible;
			aChk.selected = artistColumn.visible;
		}
		
		private function updateCheckBoxes(): void {
			pChk.enabled = !( !aChk.selected && !sChk.selected );
			sChk.enabled = !( !aChk.selected && !pChk.selected );
			aChk.enabled = !( !pChk.selected && !sChk.selected );
		}
	]]>
	</mx:Script>
 
	<mx:AdvancedDataGrid id="myGrid">
            <mx:columns>
                <mx:AdvancedDataGridColumn id="priceColumn" dataField="Price"/>
                <mx:AdvancedDataGridColumn id="storeColumn" dataField="Store"/>
                <mx:AdvancedDataGridColumn id="artistColumn" dataField="Artist"/>
			</mx:columns>	
	</mx:AdvancedDataGrid>
	
	<mx:CheckBox id="pChk" click="{priceColumn.visible=!priceColumn.visible; updateCheckBoxes()}" label="Price column visible" />
	<mx:CheckBox id="sChk" click="{storeColumn.visible=!storeColumn.visible; updateCheckBoxes()}" label="Store column visible" />
	<mx:CheckBox id="aChk" click="{artistColumn.visible=!artistColumn.visible; updateCheckBoxes()}" label="Artist column visible" />
 
</mx:Application>

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
Thanx 4 axxepting
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.